Get key and value of a JavaScript array into variable

前端 未结 6 2026
时光说笑
时光说笑 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 17:04

    am trying to get the key or value to a variable and print it.

    then you could

    var myarry = [{ one: 'one' }, { two: 'two' }];
    
    for (var key in myarry) {
      var value = myarry[key];
      console.log(key, value)
    }

提交回复
热议问题