Get key and value of a JavaScript array into variable

前端 未结 6 2030
时光说笑
时光说笑 2021-01-12 16:35

I have a JavaScript object array. When write console.log(myarry) it will show in the console in the below form.

Array[2]
0: Object
one: \"one\"         


        
6条回答
  •  情歌与酒
    2021-01-12 16:57

    check this snippet

    var obj = [{
      "1": "one"
    }, {
      "2": "two"
    }]
    obj.forEach(function(item) {
      Object.keys(item).forEach(function(key) {
        console.log("key:" + key + "value:" + item[key]);
      });
    });

    Hope it helps

提交回复
热议问题