First, say the object, how to get Key "key";
var obj={ Name: "Websong", qq:289483936 }
To get the key "name" and "QQ" for this obj object, you need to use the keys method of the built-in object, the code is as follows:
Object.keys (obj). ForEach (function (key,i,v) { console.log (key) Console.log ("---------") Console.log ( i); Console.log ("---------") Console.log (v) })
This method can output the key of the object obj as an array, and then we get it in a circular way.
Second, get the key and value of the array object
var arr=[{a:3},{b:4},{qqque:535880373}];
The truth is the same, the only thing is to loop the array first, the code is as follows:
Arr.foreach ((v,i) =>{ Object.keys (v). ForEach (v=>{ console.log (v)//takes the key Console.log (arr[i][v ])//(Value of }) })
OK, here's the end of the content. If I can help you, I am very happy.
Gets the key "key" of the object and gets the key "key" and the value of the array separately