Is there a way to effectively extract specific data from a nested array and place it into a new nested array without just pushing all the data into one array?
var selection = [0,1,3,4];
var allProductData = [['Item1Sku','Item1Name', 'Item1Desc', 'Item1Price', 'Item1Available', 'Item1Margin'], ['Item2Sku','Item2Name', 'Item2Desc', 'Item2Price', 'Item2Available', 'Item2Margin'], ['Item3Sku','Item3Name', 'Item3Desc', 'Item3Price', 'Item3Available', 'Item3Margin']]
var selectedProductData = []
for(var apd=0; apd<allProductData.length; apd++) {
for(var spd=0; spd<allProductData[apd].length; spd++) {
for(var s=0; s<selection.length; s++) {
if(allProductData[apd].indexOf(allProductData[apd][spd]) === selection[s]) {
selectedProductData.push(allProductData[apd][spd])
}
}
}
}
console.log(selectedProductData)
The current output:
[
"Item1Sku","Item1Name","Item1Price","Item1Available",
"Item2Sku","Item2Name","Item2Price","Item2Available",
"Item3Sku","Item3Name","Item3Price","Item3Available"
]
I am aiming for:
[
["Item1Sku","Item1Name","Item1Price","Item1Available"],
["Item2Sku","Item2Name","Item2Price","Item2Available"],
["Item3Sku","Item3Name","Item3Price","Item3Available"]
]
If you have any advice on how to achieve this desired result, I would greatly appreciate it.