Answers for "how to iterate array key objects in foreach"

4

object foreach

const obj = {
  name: 'Jean-Luc Picard',
  rank: 'Captain'
};

// Prints "name Jean-Luc Picard" followed by "rank Captain"
Object.keys(obj).forEach(key => {
  console.log(key, obj[key]);
});
Posted by: Guest on October-27-2020
2

foreach object javascript

Add thisvar p = {
    "p1": "value1",
    "p2": "value2",
    "p3": "value3"
};

for (var key in p) {
    if (p.hasOwnProperty(key)) {
        console.log(key + " -> " + p[key]);
    }
}
Posted by: Guest on March-27-2020

Code answers related to "how to iterate array key objects in foreach"

Code answers related to "Javascript"

Browse Popular Code Answers by Language