js remove undefined from array

104

How to Remove undefined Values From a JavaScript Array? -

// ES6+
const arr = [1, undefined, 2, 3, undefined, 5];

const filteredArr = arr.filter((elem) => elem !== undefined);

console.log(filteredArr); // output: [1, 2, 3, 5]

remove undefined element from array -

data.filter(e => e)

Comments

Submit
0 Comments