Skip to content Skip to sidebar Skip to footer

Find And Remove All Non Numbers From Array In JavaScript W/out JQuery

There was a question on a coding interview and I felt like it would be easy by using isNaN within a for loop and then splicing that index. Come to find out it didn't work and I hav

Solution 1:

Array.splice is useful here. I'm sure this solution can be optimized.

array.forEach((item, index) => typeof item !== 'number' && array.splice(index, 1));

Post a Comment for "Find And Remove All Non Numbers From Array In JavaScript W/out JQuery"