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

86
Views
Need to create a new array from old one with some changes

I have this array:

let oldarr = [{typeid:1,percent:50,key:1, name:"ger"},
              {typeid:3,percent:50,key:2, name:"geghr"},
              {{typeid:5,percent:50,key:3, name:"ggdfer"}]

I want to create a new one that looks like this:

let newarr = [{id:'', percent:''}]

The newarr's id is equal to typeid of oldarr. How to create new array?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You could achieve this using the map function:

let oldarr = [{typeid:1,percent:50,key:1, name:"ger"},
              {typeid:3,percent:50,key:2, name:"geghr"},
              {typeid:5,percent:50,key:3, name:"ggdfer"}];

let newArray = oldarr.map(item=> ({id : item.typeid, percent: item.percent}));

console.log(newArray);

about 4 years ago · Juan Pablo Isaza Report

0

let oldarr = [{typeid:1,percent:50,key:1, name:"ger"},
              {typeid:3,percent:50,key:2, name:"geghr"},
              {typeid:5,percent:50,key:3, name:"ggdfer"}]
              
let newarr=oldarr.map((e)=>{
   let {typeid,...rest}=e;
    return {
    ...rest,
    id:typeid
}
})

console.log(newarr); // your final custom array

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!