Safet Susic Safet Susic - 2 days ago 3
AngularJS Question

How to get property name and value from array

so i have object that have many properties, i need to get all values and property names from that object, i'm not sure what is best and easiest way to do it. I already tried few methods but didn't had any luck with it

angular.forEach(array, function(value, key){
console.log(value);
});

Answer

forEach works with arrays, for object properties you need:

for (var property in object) {
    if (object.hasOwnProperty(property)) {
        console.log(property, ' ', object[property];
    }
}
Comments