Firstly this thing does not need angularjs.
The way you can do that is using for each loop:
var users = [];
var positions = [{
Position0: {
title: 'Developer',
user: { name: 'Albert' }
},
Position1 : {
title: 'CEO',
user: { name: 'Smith' }
}
}]
for(var i =0; i< positions.length; i++){
for(var j in positions[i]){ //used to loop on object properties
if(positions[i].hasOwnProperty(j)){ //checking if the property is not inherited
if(positions[i][j].user){ //checking if the property exist, then only will push it to array, so that array doesnot have undefined values
users.push(positions[i][j].user);
}
}
}
}
users array will have the users.
angular.forEach
which polyfills Array.forEach. That could easily have been pertinent to the solution.{
and also}
. from what I can see it doesn't seem to be an array, instead it sounds like a single object. But if it really is an array of positions it should be like:[{title:'A', user:{}},{title:'B', user:{}}]
or at least:[{position:{title:'A', user:{}}}, {position:{title:'B', user:{}}}]