Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

109
Visualizações
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 Respostas
Responde à pergunta

0

Don't forget to check this

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

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda