Accessing Object inside Array
15,795
Solution 1
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);
Solution 2
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);
Author by
Flæx
Updated on June 04, 2022Comments
-
Flæx almost 2 years
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 returns undefined. What's the solution?
-
mplungjan almost 6 yearsPlease post CODE instead of PICTURES of code. You want
postDetail[0].author
-
Narendra Jadhav almost 6 yearswhat you have tried so far ?
-
belicam almost 6 yearspostDetail is an array and you want to access first item of it..so you need to do
postDetail[0].author
-
mplungjan almost 6 yearsThis 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.
-
-
Nicolas Pennec almost 6 yearsand just for fun, with destructuring
const [{author},] = [{"author" : "abc", "meta" : "xyz"}]; console.log(author);
:-)