let th = ['name', 'id', 'class']
let arr = [
{ 'name' : 'a', 'class':'7', 'id':'1' },
{ 'name' : 'b', 'class':'7', 'id':'2' },
{ 'name' : 'b', 'class':'7', 'id':'3' },
{ 'name' : 'd', 'class':'7', 'id':'4' }
]
/* final array what is look like */
let finalArr = [
['a', '1', '7'],
['b', '2', '7'],
['c', '3', '7'],
['d', '4', '7']
]
How can I create this array without using foreach map? This is a sample data, but in real time there are more than 10k data at a time so foreach is not a good option.
2
Answers
You have a typo in the third row, fixed here:
A potentially faster one, but actually slower up to 2x times than the above solution (tested in node.js / Chrome with 40000000 items in the
arr
, in Firefox seems the same, but it hangs on that amount of data):You may be surprised by the performance of
Array.map
/Array.forEach
(especially map). Here are performance tests for different approaches: