Two-dimensional array into a json array

An array of two-dimensional array into json -1

var colName = [
            ["08020092", "AVX",  "1200m", "120", "0.3", "30u"],
            ["08020098", "KEMET",  "1200m", "120", "1.0", "100u"],
            ["08020000", "VISHAY",  "1200m", "120", "2.5", "250u"],
        ];
        var json=[];
        colName.forEach(function(item){
            var temp={};
            item.forEach(function(value,index){
                temp[index]=value;
            });
            json.push(temp);
        })
        console.log(json)

  

Two-dimensional array into an array -2 json

var colName = [
            ["08020092", "AVX",  "1200m", "120", "0.3", "30u"],
            ["08020098", "KEMET",  "1200m", "120", "1.0", "100u"],
            ["08020000", "VISHAY",  "1200m", "120", "2.5", "250u"],
        ];
        var json=[];
        colName.forEach(function(item){
            var temp={};
                temp['name'] =item[0]
                temp['id'] =item[1]
                temp['sex'] =item[2]
                temp['op'] =item[3]
                temp['bob'] =item[4]
                temp['cat'] =item[5]
            json.push(temp);
        })
        console.log(json)

  

json array into a two-dimensional array

 var json = [{"id":"中","rowid":"华","kk":"66"},{"id":"美","rowid":"美丽","kk":"22"}] 
        var arr = [];
        for(let i in json) {
            arr[i] = [];
            for(let j in json[i]) {
                arr[i].push(json[i][j]);
            }
        }
        console.log(arr)

  

json array Gets a collection of key and value

 var json = [
            {'name':'tom'},
            {'sex':'male'}
        ]
        var keyArr = [];
        var aq = [];
        for(var i=0;i<json.length;i++){
            for(var key in json[i]){
                aq.push(json[i][key])
                keyArr.push(key)
            }
        }
        console.log(keyArr)
        console.log(aq)

  

   map usage
        Traversed by the two-dimensional map data to be processed in the practical application
       The first two-dimensional array into a set of map
var App = [[ 'dd', '123'], [ 'CC', 666], [ 'BB', 777]]; 
        var Map = new new the Map (); 
        var Map = new new the Map (App); 
        Console. log (typeof (map)) 
        map.forEach (function (value, Key) { 
            the console.log (Key, value) 
        }) 
        the console.log (map) 
        // will be converted to a two-dimensional array objects (keys in the map method , to get all the key value) 
        var Keys = []; 
        for (var key_value of map.keys ()) { 
            // the console.log (key_value) 
            keys.push (key_value) 
        } 
        the console.log (Keys) 
        var values = []; 
        for (var value of map.values ()) { 
            // the console.log (key_value)  
            values.push(value)
        }
        console.log(values)

  

Guess you like

Origin www.cnblogs.com/xinheng/p/12017259.html