Accessing Object inside Array

前端 未结 3 1032
挽巷
挽巷 2021-01-15 14:40

I\'m trying to access values inside Firebase array > object.

When I try to access values inside v-for, it works well. But I cannot do this: postDetail.author. It re

相关标签:
3条回答
  • 2021-01-15 15:06

    If you want get only author try it:

    var postDetails = [{
      author: "John",
      category: "Tech"
    }];
    
    var inner = postDetails.map(function(e) {
      return e.autor;
    });
    
    console.log(inner);

    0 讨论(0)
  • 2021-01-15 15:17

    // 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));
    });

    0 讨论(0)
  • 2021-01-15 15:24

    Since postDetail is an array of object to access properties inside its objects, you need do something like postDetail[Index].prop

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

    0 讨论(0)
提交回复
热议问题