Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

83
Views
Find list of empty indices in a javascript array

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.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

const arr = ['x', '', '', 'x', '', '', ''];
const emptyIndexes = arr.reduce((acc, curr, index) => {
  if (curr === '') {
    acc.push(index);
  }
  return acc;
}
  , []);
console.log(emptyIndexes);

about 4 years ago · Juan Pablo Isaza Report

0

roster = ["x", "", "", "x", "", "", ""]

emptyIndexArray = []

for (i = 0; i < roster.length; i++) {
  if (roster[i] === "") {
    emptyIndexArray[emptyIndexArray.length] = i;
  }
}

emptyIndexArray.forEach(x => console.log(x));

about 4 years ago · Juan Pablo Isaza Report

0

arr.map((item, index) => item === '' ? index : null).filter(item => item)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!