javascript - How to loop through an object and print out the string of the object itself
为情所困
为情所困 2017-05-19 10:25:05
0
6
498
var a = {a:1,b:2}

var b = {a:2,b:3}

[a,b].forEach(key => {
    console.log(key)    
})

Maybe the expression is not very clear. Please add a picture

为情所困
为情所困

reply all(6)
洪涛
[a, b].forEach(key => {
  console.log(JSON.stringify(key))
})
过去多啦不再A梦
var a = {a:1,b:2};
var b = {a:2,b:3};
[a,b].forEach(obj => {
    for (key in obj) {
        console.log(obj[key]);
        }
    })
我想大声告诉你
obj = {
    a: {},
    b: {}
}

for(key in obj) {
    console.log(key)
}

I still don’t quite understand the result you want

刘奇
[a,b].forEach(obj => {
    for(key in obj) {
        console.log(key)
    }
})
黄舟
[a, b].forEach( (v) => console.log(v));
// { a: 1, b: 2 }
// { a: 2, b: 3 }

[a, b].forEach( (v) => {
  for(key in v) {
    console.log(key)
  }
});
// a
// b
// a
// b

[a, b].forEach( (v) => {
  var {a, b} = v;
  console.log(a, b);
});
// 1 2
// 2 3
Peter_Zhu

That’s it - output a:1 b:2 a:2 b:3

        [a, b].forEach(el => {
            for (let key in el) {
                console.log(`${key}:${el[key]}`)
            }
        });
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template