访问内部数组对象

问题描述 投票:2回答:3

我试图访问火力地堡阵列>对象中值。 enter image description here

当我尝试访问内部V型的值,它工作得很好。但我不能这样做:postDetail.author。它返回undefined。有什么解决办法?

javascript vue.js nuxt.js
3个回答
1
投票

由于postDetail是对象的其对象中访问属性数组,你需要做这样的事情postDetail[Index].prop

var postDetail =[{"author" : "abc", "meta" : "xyz"}];
console.log(postDetail[0].author);

1
投票

如果你想只得到author试试吧:

var postDetails = [{
  author: "John",
  category: "Tech"
}];

var inner = postDetails.map(function(e) {
  return e.autor;
});

console.log(inner);

0
投票

// Array of object
var persons = [
  {
    name: "shubham",
    age: 22,
    comments: ["Good", "Awesome"]
  },
  {
    name: "Ankit",
    age: 24,
    comments: ["Fine", "Decent"]
  },
  {
    name: "Arvind",
    age: 26,
    comments: ["Awesome", "Handsome"]
  },
  {
    name: "Ashwani",
    age: 28,
    comments: ["Very Good", "Lovely"]
  }
];

var data = persons.map(person => {
  console.log(person.name);
  console.log(person.age);
  person.comments.map((comment, index) => console.log(index + " " + comment));
});
© www.soinside.com 2019 - 2024. All rights reserved.