var things = [], x;
for(x in $scope.object){
if($scope.object.hasOwnProperty(x)){
if($scope.object[x].content !== undefined){
things.push($scope.object[x].content);
}
}
}
This covers all checks you should require to make sure its working. Tested:
var $scope = {};
$scope.object = {
'thing1': {
'content': 'blah blah',
'order': '1',
},
'thing2': {
'content': 'blah blah blah',
'order': '2',
}
};
var things = [], x;
for(x in $scope.object){
if($scope.object.hasOwnProperty(x)){
if($scope.object[x].content !== undefined){
things.push($scope.object[x].content);
}
}
}
console.log(things);//logs ["blah blah", "blah blah blah"]
Object.hasOwnProperty(propertyName)
is required to make sure that the object has actually been given that property, .content
makes sure that the property is there and the value is not undefined.
In the instance of:
for(var x in object)
x
is actually the property name, in this case thing1
and thing2
, if object is replaced by an array then x will be the index of each object.