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

81
Visualizações
make a dimensional array from object

I get this data from the backend

let procedure_word_count = [{"slug":"new","name":"New","count":1},{"slug":"no-need","name":"No Need","count":2},{"slug":"why","name":"Why","count":2}]

My goal is to create a dimensional array that extracts the name and count from the "procedure_word_count"

let newArray = "[['New', 1], ['No Need', 2], ['Why', 2]]"
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You can always map it and create an array from the object:

let example = [
  {"slug":"new","name":"New","count":1},
  {"slug":"no-need","name":"No Need","count":2},
  {"slug":"why","name":"Why","count":2}
];

let result = example.map((item) => [item.name, item.count]);
console.log(result);

about 4 years ago · Juan Pablo Isaza Relatório

0

The map method creates a new array with the results of calling a function for every array element so it's a classic for this one. for each iteration the function will return an array containing the selected keys values.

const arr = [{"slug":"new","name":"New","count":1},{"slug":"no-need","name":"No Need","count":2},{"slug":"why","name":"Why","count":2}];

const res = arr.map(x => [x.name, x.count]);
console.log(res);

about 4 years ago · Juan Pablo Isaza Relatório

0

The JSON you retrieve from the server can be iterated over using the .map() method.

.map() iterates over each element and builds an array.. The function returns whatever you want - in this case the name and count properties.

const input = [{"slug":"new","name":"New","count":1},{"slug":"no-need","name":"No Need","count":2},{"slug":"why","name":"Why","count":2}];

const output = input.map(o=>[o.name,o.count]);

console.log(output);

about 4 years ago · Juan Pablo Isaza 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