我在变量
中收到以下数据let data = [
[{option: “foo0", value: “bar0”}],
[{option: “foo1", value: “bar1”}],
[{option: “foo2", value: “bar2”}],
[{option: “foo3", value: “bar3”}],
]
我需要将响应更改为
[
{option: “foo0", value: “bar0”},
{option: “foo1", value: “bar1”},
{option: “foo2", value: “bar2”},
{option: “foo3", value: “bar3”},
]
我怎么能在JS中做到这一点
答案 0 :(得分:5)
试试这个:
let data = [
[{
option: "foo0",
value: "bar0"
}],
[{
option: "foo1",
value: "bar1"
}],
[{
option: "foo2",
value: "bar2"
}],
[{
option: "foo3",
value: "bar3"
}],
];
let result = data.map(v => v[0]);
console.log(result);
答案 1 :(得分:3)