gpt4 book ai didi

javascript - 转换和数组

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:01:08 26 4
gpt4 key购买 nike

我有这样的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com