我有这个对象数组
[{
"A": "thisA",
"B": "thisB",
"C": "thisC"
}, {
"A": "thatA",
"B": "thatB",
"C": "thatC"
}]
Run Code Online (Sandbox Code Playgroud)
我试图将这种格式作为最终结果: [["thisA","thisB","thisC"], ["thatA","thisB","thatC"]]
我知道我们可以使用map()函数和特定键(A,B,C).
newarray = array.map(d => [d['A'], d['B'], d['C']])
Run Code Online (Sandbox Code Playgroud)
但我需要一个通用的功能来转移它而不使用密钥,因为数组的内容会有所不同,关键会有所不同.有什么好的解决方案吗?
const arr = [{
"A": "thisA",
"B": "thisB",
"C": "thisC"
}, {
"A": "thatA",
"B": "thatB",
"C": "thatC"
}]
const result = arr.map(Object.values)
console.log(result);Run Code Online (Sandbox Code Playgroud)