Issue
I have an array that looks like this
const array: any[] = []
array.push({ 'Comments': this.comment, 'Name': this.name, 'Description' : this.description })
I pass that array back to a parent component. How can I grab the value that is in Comments?
Solution
You can use forEach loop :
const commentArray = [];
array.forEach(function(object) {
var comment = object.Comments;
commentArray.push(comment);
});
//You can store all comments in another array and use it...
console.log("This is comment array...", commentArray);
Or use map but it will work in new browsers possibly ones following ES6:
const commentArray = array.map(function(object) {
return object.Comments;
});
console.log("This is comment array... ", commentArray);
Answered By - TGW
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.