Javascript objects do not have an order associated with them by definition, so this is not possible .
You need to use an array of objects if you need an order:
var myArray = [
{number: '9', value:'Automotive & Industrial'},
{number: '1', value:'Books'},
{number: '7', value:'Clothing'}
]
then if you want to insert something in the first position, you can use the unshift method for arrays.
myArray.unshift({number:'5', value:'Electronics'})
[{number:'5', value:'Electronics'},
{number: '9', value:'Automotive & Industrial'},
{number: '1', value:'Books'},
{number: '7', value:'Clothing'}]
more details here:
Is the order for the JavaScript property object guaranteed?
source
share