Is there a way in Javascript to find the indices where an array is empty or doesnt contain "x"?
["x", "", "", "x", "", "", ""]
Would return something like:
[1,2,4,5,6]
I have attempted something like this:
empty = roster.findIndex((obj) => Object.keys(obj).length === 0)
However I can't come up with a way to iterate over the list.
const arr = ['x', '', '', 'x', '', '', ''];
const emptyIndexes = arr.reduce((acc, curr, index) => {
if (curr === '') {
acc.push(index);
}
return acc;
}
, []);
console.log(emptyIndexes);
roster = ["x", "", "", "x", "", "", ""]
emptyIndexArray = []
for (i = 0; i < roster.length; i++) {
if (roster[i] === "") {
emptyIndexArray[emptyIndexArray.length] = i;
}
}
emptyIndexArray.forEach(x => console.log(x));
arr.map((item, index) => item === '' ? index : null).filter(item => item)