Trying to make a function that removes only the "strings" from the array. I'm looking to only have the numbers left. I've already accomplished this by adding numbers only to a newArray, and I was looking into the splice method but could not figure out how to write it. As you see in code delete works, but returns undefined in its spot.
function numbersOnly(arr){
for(var i = 0; i < arr.length; i++){
if(typeof arr[i] === "string"){
delete arr[i];
}
}
console.log(arr);
}
numbersOnly([1, "apple", -3, "orange", 0.5, 22, "hello", 6])
returns [1, undefined, -3, undefined, 0.5, 22, undefined, 6]