varArray = [12,3,67,88,9,344,78,6];varobj1 = {' name ': ' Kobayashi ', ' age ': ' + ', ' sex ': ' Male '};varObj2 = [{' Name ': ' Xiaoming '},{' age ': '},{' sex ': ' Men '},{' sport ': ' Basketball '}];varKeys = [],values = [];//traversing the obj1 used to store keys and valuesvarKeys2 = [],values2 = [];//traversing the OBJ2 used to store keys and valuesArray.Sort (function(x, Y) {//methods for sorting ordinary arrays returnX-y;}) varloop =function(obj) {//methods for finding the keys and values of ordinary objects for(varKeyinchobj) {Keys.push (key); Values.push (Obj[key]); } console.log (Keys.tostring ()+ '------' +values.tostring ());} varLOOP2 =function(obj) {//methods for finding the key and value of an array object for(vari=0;i<obj.length;i++){ for(varKeyinchObj[i]) {Keys2.push (key); Values2.push (Obj[i][key]); }} console.log (Keys2.tostring ()+ '------' +values2.tostring ());} Console.log (Array.tostring ()); Loop (obj1); Loop2 (OBJ2) ;
Array of sorted arrays and objects that traverse the key-value pairs of ordinary objects and how to traverse a different key value