I have a large JSON object where I can access the the value I want like so:
$scope.customers[1][data]["DisplayName"];
However, that references the DisplayName of only one object.
Is there an easy way to return all DisplayName properties from the entire collection?
i.e.
$scope.customers[*][data]["DisplayName"];
Or is the only way to do this by creating a new JSON object by looping through the original?
You can use map() function of Array. It applies the callback function to each element of array and produces new array:
[1,2,3].map(function(num) { return num * num }); // returns [1, 4, 9]
In your case you can use:
$scope.customers.map(function(element) { return element[data]["DisplayName"]; } );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With