I’m new to underscore so pardon my ignorance.
Is there a quick and easy way to do the following:
men:{gerald:{"name":"Gerald", "age":50},mike:{"name":"Mike", "age":50},charles:{"name":"Charles", "age":50}}
Where name is Mike – set at position 1 (index 0)
I just want to shuffle the items so the first item is set by the name I choose.
Any help more than welcome.
You don’t need underscore.js.
Array.sortwill do fine:This isn’t really model usage of sort, but it does the job.
Also, your JSON is invalid. You need square brackets around the array, not curlies:Edit:
You can’t “order” that JSON. What you’re asking to do is order an associative array. This doesn’t make any sense. If order of items is important, you want an array, not an object.