我有这样的 arr
[{
"ID": "this THE ID",
"NAME": "this THE NAME",
"AGE": "thiS THE AGE"
}, {
"ID": "that ID",
"NAME": "that THE NAME",
"AGE": "that THE AGE"
}]
我希望达到这样的结果:
[["this THE ID","this THE NAME","thiS THE AGE"], ["that ID","that THE NAME","that THE AGE"]]
我尝试了什么
var result = []
data.forEach(function(ID,NAME,AGE) {
result.push(ID)
result.push(NAME)
result.psuh(AGE)
});
但是我没有得到我想要的正确结果
最佳答案
在这种情况下, map 是你最好的 friend
var arr = [{
"ID": "this THE ID",
"NAME": "this THE NAME",
"AGE": "thiS THE AGE"
}, {
"ID": "that ID",
"NAME": "that THE NAME",
"AGE": "that THE AGE"
}]
const result = arr.map(({ID,NAME,AGE}) => [ID,NAME,AGE]);
console.log(result)
关于javascript - 转换和数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49469857/