I use this code to iterate on the JavaScript objects array and return value:
this.selectedClient = _.forEach(self.clients, function (client) {
if (client.IdentityNumber == -1) {
return client;
}
})
this.clients=[{firstName:"Tywin", lastName:"Lannister", age:46, IdentityNumber:2},
{firstName:"Arya", lastName:"Starck", age:46, IdentityNumber:-1},
{firstName:"John", lastName:"Snow", age:46, IdentityNumber:12},
{firstName:"Robb", lastName:"Starck", age:46, IdentityNumber:24}];
But after iteration is done I expect that selectedClient veriable will get single item:
{firstName:"Arya", lastName:"Starck", age:46, IdentityNumber:-1}
But instead selectedClient veriable get all items in clients variable.
Any idea why I can't get single value after iteration on clients variable?