在JavaScript数组中打印特定属性
当我打印它在数组下面打印的变量时,是否有方法从下面的数组打印OwnerId在JavaScript数组中打印特定属性,javascript,reactjs,react-native,expo,Javascript,Reactjs,React Native,Expo,当我打印它在数组下面打印的变量时,是否有方法从下面的数组打印OwnerId Array [ Place { "lng": -0.0109167, "ownerId": test, "title": "Test", }, Place { "lng": -0.0108539, "ownerId": 234, "t
Array [
Place {
"lng": -0.0109167,
"ownerId": test,
"title": "Test",
},
Place {
"lng": -0.0108539,
"ownerId": 234,
"title": "Server test",
},
Place {
"lng": -0.0108778,
"ownerId": 234,
"title": "Tile",
},]
以下是您想要的:
const a=[{
“液化天然气”:-0.0109167,
“所有者ID”:435,
“标题”:“测试”,
}, {
“液化天然气”:-0.0108539,
“所有者ID”:234,
“标题”:“服务器测试”,
}, {
“液化天然气”:-0.0108778,
“所有者ID”:234,
“标题”:“瓷砖”,
}];
console.log(a.map(x=>x.ownerId))
什么是Place
?这是变量.toString()
的输出吗?Place是一个类名:class Place{constructor(lng,ownerId,title){this.lng=lng;this.ownerId=ownerId;this.title=title;}}听起来你想在一行中做点什么,对吗?