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\
You could use Map()
A Map object iterates its elements in insertion order
var arr = ['red', 'green', 'blue', 'yellow']; var map = new Map(); arr.forEach(function(val, index) { var obj = {}; obj[val] = []; map.set(index, obj) }); console.log(map)