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

190
Visualizações
indexing data arrays in reverse manner (newest data get the last no. since my data are arranged from newest to oldest which means from last to first)

I have indexed my array(posts) through the code below. The problem is that I need to index them in a reverse manner (from larger to lower) since my data is displayed from the newest to oldest so I want the newest post get the last index no. in the array which now is the opposite(newest get no 0). Also, how can I start indexing from no. 1 not 0 any ideas?

  this.posts.forEach((post, index) => {post.index = index})
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Now what I understood as per the above comments, You want to index the newest post with last index and oldest with the first index. If Yes, You can do this by using Array.map() :

const posts = ['newest', 'old', 'oldest'];

const res = posts.map((post, index) => {
    return {
    name: post,
    index: posts.length - index
  }
});

console.log(posts); // original array without mutate
console.log(res); // New array of objects with index properties

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