gpt4 book ai didi

javascript - 如何在不使用 key 的情况下将json转换为数组

转载 作者:行者123 更新时间:2023-11-30 07:50:32 25 4
gpt4 key购买 nike

我有这个对象数组

[{
"A": "thisA",
"B": "thisB",
"C": "thisC"
}, {
"A": "thatA",
"B": "thatB",
"C": "thatC"
}]

我试图将这种格式作为最终结果:[["thisA","thisB","thisC"], ["thatA","thisB","thatC"]]

我知道我们可以使用具有特定键(A、B、C)的 map() 函数。

newarray = array.map(d => [d['A'], d['B'], d['C']])

但是我需要一个通用的函数来传递它而不使用key,因为数组的内容会不同,key也会不同。有什么好的解决办法吗?

最佳答案

const arr = [{
"A": "thisA",
"B": "thisB",
"C": "thisC"
}, {
"A": "thatA",
"B": "thatB",
"C": "thatC"
}]

const result = arr.map(Object.values)

console.log(result);

关于javascript - 如何在不使用 key 的情况下将json转换为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53881337/

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