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

189
Views
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 answers
Answer question

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 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!