Adsense

jquery json keys sort

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

var txt= "3.0.2.96 3.0.2.106 3.0.2.100 3.0.2.101"
console.log(txt)
var BuildValue = txt.split(' ').map(function(txt){return txt});
//var BuildValue =["a", "d", "c", "b"]
var buildId = ["857", "868", "861", "862"]
console.log(BuildValue)
console.log(buildId)

var c = {};
$.each( BuildValue, function(item,v) {
  c[ v ] = buildId[ item ];
});

console.log("c "+c)

 keys = Object.keys(c).sort();

console.log(keys);

for (var i = 0; i < keys.length; i++) {
    var key = keys[i] // totally unnecessary readability enhancement
     console.log(key+": "+c[key])
}


output

3.0.2.96 3.0.2.106 3.0.2.100 3.0.2.101
 ["3.0.2.96", "3.0.2.106", "3.0.2.100", "3.0.2.101"]
 ["857", "868", "861", "862"]
 c [object Object]
 ["3.0.2.100", "3.0.2.101", "3.0.2.106", "3.0.2.96"]
 3.0.2.100: 861
 3.0.2.101: 862
 3.0.2.106: 868
 3.0.2.96: 857

8 comments:

comment here

newest questions on wordpress