Get key and value of a JavaScript array into variable

前端 未结 6 2023
时光说笑
时光说笑 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:18

    you can do it in this way

    const a = [{ one: 'one' }, { two: 'two' }];
    
    a.forEach(function(value,key) {
       console.log(value,key);
    });

    You can take key and value in a variable and use them.

提交回复
热议问题