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

120
Views
Javascript: How to iterate only a certain part of a javascript object?

I have a javascript object that looks like this

const columns = {
    firstLabel: 'Hello',
    secondLabel: 'world',
    thirdLabel: 'I',
    fourthLabel: 'Am',
    fifthLabel: 'Paul',
};

I am trying to only get the values of the last three I, Am, Paul. I am doing something like this but this clearly doesn't work as this will return everything. Is this possible to do with an object?

 for(const prop in columns) {
      if(Object.keys(columns).length > 2){
        console.log(`${columns[prop]}`);
      }
 }

Expected output is just:

I

Am

Here

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Try with,

const lastThree = Object.values(columns).slice(-3);
console.log(lastThree);

The answer is:

[ 'I', 'Am', 'Paul' ]
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!