0

I was trying to add value to textarea from scope's array starting with new line and i found a good example here but seems like it works only with array of primitives.

$scope.names = ['morpheus', 'neo', 'trinity'];

But what if i need to use array of js objects like this:

$scope.namesObj = [
            {name: 'morpheus'},
            {name: 'neo'},
            {name: 'trinity'}
         ]

As you can see in this example it shows only

[object Object]
[object Object]
[object Object]

I can't find a way how to get property name. Thanks in advance!

1 Answer 1

1

Not sure I understood your question...but if you just want an easy way to deal with non-primitive objects in your array, you may use https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

$scope.namesObj = [
    {name: 'morpheus'},
    {name: 'neo'},
    {name: 'trinity'}
]
.map(function(item){
    return item.name;
});

Here's your updated plunker: http://plnkr.co/edit/xShKGn2DwMZPgpK319V5?p=preview

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

1 Comment

Yes. that's exactly what i wanted! Thank you a lot.

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.