1let obj = {
2 key1: "value1",
3 key2: "value2",
4 key3: "value3",
5 key4: "value4",
6}
7Object.entries(obj).forEach(([key, value]) => {
8 console.log(key, value);
9});
1var person={
2 first_name:"johnny",
3 last_name: "johnson",
4 phone:"703-3424-1111"
5};
6for (var property in person) {
7 console.log(property,":",person[property]);
8}
1let person={
2 first_name:"johnny",
3 last_name: "johnson",
4 phone:"703-3424-1111"
5};
6for (let i in person) {
7 let t = person[i]
8 console.log(i,":",t);
9}
1var obj = {
2 first: "John",
3 last: "Doe"
4};
5
6//
7// Visit non-inherited enumerable keys
8//
9Object.keys(obj).forEach(function(key) {
10
11 console.log(key, obj[key]);
12
13});
1let obj = {
2 key1: "value1",
3 key2: "value2",
4 key3: "value3"
5}
6
7Object.keys(obj).forEach(key => {
8 let value = obj[key];
9 //use key and value here
10});
1for (let key in yourobject) {
2 if (yourobject.hasOwnProperty(key)) {
3 console.log(key, yourobject[key]);
4 }
5}