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

92
Views
JS - map array from another array

I want to change the array

transactionProducts: [{
sku: "SKU_12345",
name: "Stan and Friends Tee",
}]

to

items: [{
item_id: "SKU_12345",
item_name: "Stan and Friends Tee",
}]

I tried below:

var items = transactionProducts.map (({sku,name}) =>
 ({item_id:sku,item_name:name}));
return items;
} 

but I soon find the EC6 version is not allowed in my environment, so I have to use older version (meaning cannot use arrows)

How can I do?

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

0

You were pretty close

ES5:

const transactionProducts = [
    {
        sku: 'SKU_12345',
        name: 'Stan and Friends Tee',
    },
    {
        sku: 'SKU_12365',
        name: 'Stan and Friends Pants',
    },
];

const mapped = transactionProducts.map(function (obj) {
    return {
        item_id: obj.sku,
        item_name: obj.name,
    };
});

console.log(mapped);

about 4 years ago · Juan Pablo Isaza Report

0

You can use normal function and there is no destructuring in before ES6 so you can directly access properties from object using dot(.) notation

var transactionProducts = [
    {
        sku: 'SKU_12345',
        name: 'Stan and Friends Tee',
    },
];

var items = transactionProducts.map(function (obj) {
    return { item_id: obj.sku, item_name: obj.name };
});

console.log(items);

about 4 years ago · Juan Pablo Isaza Report

0

This would be ES5 version

var items = transactionProducts.map(function(obj) {
  return {
    item_id: sku,
    item_name: name,
  }
})
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!