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

103
Views
How do I filter through an array of arrays using an index in JavaScript?

Im'm working on a JavaScript side prokect and I've got a json file with an array with arrays like this:

arr = 

{
  "values": [
    ["Form Factor", "OS"],
    ["Landscape", "Android 9\n(Source)"],
    ["Portrait", "Analogue OS"],
    ["Micro\nLandscape", "?"]
  ]
}

The first array with "Form factor" (index 0) are the headlines. If I want to get all the "form factors" from the arrays how would I do that?

I know that "Form Factor" has index 0 but how do i filter through several arrays at once with an index? in the end I want an array like

results = ["Form Factor", "Landscape", "Portrait", "Micro\nLandscape"]

I tried it like this:

const index = 0;
const result = this.arr.values.filter(function (eachElem) {
        return eachElem == index;
      });

But that just gives me back an empty array.

about 4 years ago · Santiago Gelvez
3 answers
Answer question

0

Don't forget to check this

arr.values.map(x => x[0])
about 4 years ago · Santiago Gelvez Report

0

Your code isn't working because a) index isn't defined, you need to also put it as a parameter and b) in your case no element will be true. I would use a traditional for loop in your case but surely if you want you can do it with es6 magic.

let result = [];
for (let i = 0; i < arr.values.length; i++) {
    result.push(arr.values[i][0]);
}
console.log(result);
about 4 years ago · Santiago Gelvez Report

0

Just use array.find() it's much easier and you can search for your element in your array:

const found = array1.find(element => element > 10);

about 4 years ago · Santiago Gelvez 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!