Calculate distance from GPS data 我如何获得id的值以及如何将多个对象合并为单个数组
另外为了更多的参考,我在这里有一个对象,我想要它的id值
var myObj = {
"cars": [
{
"id": 1,
"name": "Ford",
"models": ["Fiesta", "Focus", "Mustang"]
},
{
"id": 2,
"name": "BMW",
"models": ["320", "X3", "X5"]
},
{
"id": 3,
"name": "Fiat",
"models": ["500", "Panda"]
}
]
}
please click me 我如何在浏览器中打印id
id - 1 name - ford
id - 2 名字 - 宝马
.......
喜欢这样
答案 0 :(得分:1)
用lodash:
_.map(myObj.cars, x => x.id)
与es6:
myObj.cars.map(x => x.id)
答案 1 :(得分:0)
console.log(myObj.cars[0].id); // output: 1
console.log(myObj.cars[1].id); // output: 2
console.log(myObj.cars[2].id); // output: 3