我有一个像这样的数据
[
{
"3": "Foundation in Business",
"4": "0",
"5": "1103267.5",
"6": "4277417.5",
"7": "5168625",
"8": "6241805",
"9": "7383665",
"10": "8236385",
"11": "8645050",
"12": "2494100",
"13": "155555"
}
]
我希望它像这样
数据:[ “商业基础”, “0”, “1103267.5”, “4277417.5”, “5168625”, “6241805”, “7383665”, “8236385”, “8645050”, “2494100”, “155555” ]
请帮帮我...
答案 0 :(得分:1)
在ES6中,映射值并获取Object值。因为结果是另一个数组得到第一个元素。如果你有一个对象数组,你可以通过删除脚本末尾的[0]来获得一个数组数组。
const jsonObject = [{
"3": "Foundation in Business",
"4": "0",
"5": "1103267.5",
"6": "4277417.5",
"7": "5168625",
"8": "6241805",
"9": "7383665",
"10": "8236385",
"11": "8645050",
"12": "2494100",
"13": "155555"
}];
const data = jsonObject.map(v => Object.values(v))[0];
console.log(data);
在跨浏览器支持的标准中,你可以这样做:
const jsonObject = [{
"3": "Foundation in Business",
"4": "0",
"5": "1103267.5",
"6": "4277417.5",
"7": "5168625",
"8": "6241805",
"9": "7383665",
"10": "8236385",
"11": "8645050",
"12": "2494100",
"13": "155555"
}];
var array = [];
for (var name in jsonObject[0]) {
console.log(name);
array.push(jsonObject[0][name]);
}
console.log(array);