I am trying to custom sort a JavaScript object but not able to get how we can do this in a right way. Say I am having an object like
var test = {
\'yellow\
May be you could change this using JSON.stringify()
do like
var json = { "name": "David", "age" : 78, "NoOfVisits" : 4 };
console.log(json);
//outputs - Object {name: "David", age: 78, NoOfVisits: 4}
//change order to NoOfVisits,age,name
var k = JSON.parse(JSON.stringify( json, ["NoOfVisits","age","name"] , 4));
console.log(k);
//outputs - Object {NoOfVisits: 4, age: 78, name: "David"}
put the key order you want in an array and supply to the function. then parse the result back to json.