Return Only Strings
Published in
Sep 30, 2020
Q. Create a function that takes an array of non-negative integers and strings and return a new array without the strings.
const filterArray = function(arr) { console.log(arr.filter(arr => typeof arr === 'number'));}filterArray([1, "2", "a", 3]); // should be [1, 3]
- Extract elements and create a new array with
filter()
method. - Add condition with
typeof
operator, the element should be extracted when it is number.