for Each

for Each function

by Mehmetcan Sinir

JavaScript

//arrays forEach

var people = [
    {
        name: "Mehmetcan",
        age: 28,
        job: ""
    },
    {
        name: "Sibel",
        age: 58,
        job: "real estate agent"
    },
    {
        name: "Deniz",
        age: 27,
        job: "account manager"
    },
    {
        name: "Emin",
        age: "63",
        job: "translator"
    }
]

/*build a function that logs the property values of the object elements of the people array*/


function logPropertyValues () {
    people.forEach(function(eachElement) {
        for (var eachItem in eachElement) {
            console.log(eachElement[eachItem]);
            //if property name is in variable you have to use bracket notation
        }
    })
}
                
 logPropertyValues();