loop through object and return array javascript code example
Example 1: javascript loop through object example
var person={
first_name:"johnny",
last_name: "johnson",
phone:"703-3424-1111"
};
for (var property in person) {
console.log(property,":",person[property]);
}
Example 2: js loop array of objects
const p = [{
"p1": "value1",
"p2": "value2",
"p3": "value3"
},
{
"p4": "value4",
"p5": "value5",
"p6": "value6"
}];
for (let obj of p) {
for(let key in obj) {
console.log(key);
}
}
Example 3: how to loop through an array of objects+
var arr = [[1,2], [3,4], [5,6]];
for (var i=0; i < arr.length; i++) {
for (var j=0; j < arr[i].length; j++) {
console.log(arr[i][j]);
}
}