2

I'm trying to access values inside Firebase array > object. enter image description here

When I try to access values inside v-for, it works well. But I cannot do this: postDetail.author. It returns undefined. What's the solution?

4
  • 3
    Please post CODE instead of PICTURES of code. You want postDetail[0].author Commented Jun 12, 2018 at 16:59
  • what you have tried so far ? Commented Jun 12, 2018 at 16:59
  • postDetail is an array and you want to access first item of it..so you need to do postDetail[0].author Commented Jun 12, 2018 at 17:01
  • This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting. Commented Jun 12, 2018 at 17:02

3 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

and just for fun, with destructuring const [{author},] = [{"author" : "abc", "meta" : "xyz"}]; console.log(author); :-)
1

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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.