I have an object with the following values:
const data = {
"generalInfo": [{
"title": "title1",
"permalink": "www.link.com",
"manufacturer": "manufacturer1",
"category": [{
"term_id": 35,
"name": "Motherboard",
"slug": "motherboard"
}],
"img": "https://images-na.ssl-images-test.com/images/asdfIdR/5adf1vELadfZeiMML.jpg",
"curreny": "$",
"price": "64.00",
"availability": "Usually ships in 24 hours",
},
{
"title": "title2",
"permalink": "www.link.com",
"manufacturer": "manufacturer2",
"category": [{
"term_id": 35,
"name": "Motherboard",
"slug": "motherboard"
}],
"img": "https://images-na.ssl-images-test.com/images/I/51adfkLhadsfgACH0L.jpg",
"curreny": "$",
"price": "59.99",
"availability": "Usually ships in 24 hours",
}
]
}
// console.log(typeof(data))
var vals = Object.keys(data).map(function(key) {
return data[key]
})
console.log(vals)
// expected output
// [ "1", "title1", "manufacturer1", "64.00", "Usually ships in 24 hours", "", "" ],
// [ "2", "title2", "manufacturer2", "59.99", "Usually ships in 24 hours", "", "" ],
I am attempting to utilize Object.keys(data).map
to form an array structure from my object. However, I am getting an array nested within another array containing 2 objects. But, I am aiming for the desired output shown below:
// expected output
// [ "1", "title1", "manufacturer1", "64.00", "Usually ships in 24 hours", "", "" ],
// [ "2", "title2", "manufacturer2", "59.99", "Usually ships in 24 hours", "", "" ],
If you have any suggestions on how to transform the array to achieve the above results, please let me know.
Your input is greatly appreciated!