CodeMan03 CodeMan03 - 3 years ago 196
TypeScript Question

How to get a value out of an array in typescript?

I have an array that looks like this

const array: any[] = []
array.push({ 'Comments': this.comment, 'Name':, 'Description' : this.description })

I pass that array back to a parent component. How can I grab the value that is in Comments?

Answer Source

You can use forEach loop :

array.forEach(function(object) {
    var comment = object.Comments;
//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:

commentArray = {
    return object.Comments;
console.log("This is comment array... ", commentArray);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download