I have an array of objects that I need to reformat into a list of arrays in a specific format.
I need my list to be formatted like this
list: [
[ "B", "A" ],
[ "F", "E" ],
]
But the closest I have come is this
list: ["B A", "F E"]
using this code
const itemList = [
{"ProductName":"A",
"Sku":"B",},
{"ProductName":"E",
"Sku":"F",}
];
const newList = itemList.map(item => `${item.Sku} ${item.ProductName}`);
console.log(newList);
How would I map this correctly?
You can create array with the values inside map:
const itemList = [
{"ProductName":"A",
"Sku":"B",},
{"ProductName":"E",
"Sku":"F",}
];
const newList = itemList.map(item => [item.Sku, item.ProductName]);
console.log(newList);