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

211
Views
JS add all items into one array using map

I have an object:

[
    {
        "id": 10,
        "name": "comedy"
    },
    {
        "id": 12,
        "name": "documentary"
    },
    {
        "id": 11,
        "name": "scifi"
    }
]

I need to take only the id values and add them into 1 array like so:

[ 10, 12, 13 ]

or

{ 10, 12, 13 }

I am trying:

const getIDs = value.map( ( { id } ) => ( {
  id: id
} ) );

But it creates:

[
    {
        "id": 10
    },
    {
        "id": 12
    },
    {
        "id": 11
    }
]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Inside the map just return the id values instead of objects

Here is the quick solution

const values = [
    {
        "id": 10,
        "name": "comedy"
    },
    {
        "id": 12,
        "name": "documentary"
    },
    {
        "id": 11,
        "name": "scifi"
    }
]


const getIDs = values.map(({id}) => id);

console.log(getIDs)

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!