How to sort keys in json by another json values

拜拜、爱过 提交于 2021-02-11 14:40:46

问题


I have two jsons.

First: here

Second: here

How to sort second json by first? I want to sort keys and it's values in second json by values in first json.


回答1:


You could do something like this

var first = ["name0", "name1", "name2"]
var second = { {"name2":"xyz", "name0" : "xyz", "name1" : "xyz" } } 
for( var i = 1; i < Object.keys(second).length; i++ ){
  var aux = {}
  first.forEach(function(element2) {
     resul[element2] = second[i][element2]
  });
}


来源:https://stackoverflow.com/questions/54029071/how-to-sort-keys-in-json-by-another-json-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!