Is there a way in JavaScript to retrieve the indexes of undefined array elements without using a loop? Possibly utilizing a combination of map, filter, and indexOf?
I have a loop solution that I'm seeking an alternative for - something more concise, like a one-liner:
const sourceArray = [,1,undefined,3];
const filteredArray = [];
for (let i = 0; i < sourceArray.length; i++) {
if (sourceArray[i] === undefined) filteredArray.push(i);
}
console.log(filteredArray); // [0,2]