Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
18
rated 0 times [  24] [ 6]  / answers: 1 / hits: 17136  / 7 Years ago, sat, september 30, 2017, 12:00:00

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?


More From » angularjs

 Answers
44

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

[#56341] Thursday, September 28, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
breap

Total Points: 606
Total Questions: 96
Total Answers: 108

Location: Djibouti
Member since Sun, Feb 27, 2022
2 Years ago
breap questions
Thu, Jun 24, 21, 00:00, 3 Years ago
Wed, Mar 18, 20, 00:00, 4 Years ago
Mon, Oct 7, 19, 00:00, 5 Years ago
;