// ES6+ const arr = [1, undefined, 2, 3, undefined, 5]; const filteredArr = arr.filter((elem) => elem !== undefined); console.log(filteredArr); // output: [1, 2, 3, 5]
data.filter(e => e)