After making a call to an external service, I receive a domain object in return:
var domainObject = responseObject.json();
This JSON object can then be easily accessed to retrieve specific properties. For example:
var users = domainObject.Users
The 'Users' property contains key/value pairs, such as:
1: "Bob Smith"
2: "Jane Doe"
3: "Bill Jones"
However, Chrome Developer Tools (CDT) displays the 'users' variable as type Object, and users[0] returns undefined. How can I access the first item in this collection? It seems that some type of type casting may be necessary, but the process is unclear.
LATEST UPDATE
An alternative approach for accessing the values is shown below:
//get first user key
Object.keys(responseObject.json().Users)[0]
//get first user value
Object.values(responseObject.json().Users)[0]
Since I also need to bind data through ng2, I was hoping for a simpler method like the one illustrated here:
<div>
<div *ngFor="let user of users">
User Name: {{user.value}}
<br>
</div>
</div>
Perhaps it would be best to create a conversion function within my ng2 component to transform the object into the required format before setting the databinding variable?