lundi 18 septembre 2017

How do I add key:value pair in an order in javascript.

I need to add key:value into an object.

var a = {}
a['first'] = [a,bunch,of,stuff]
a['eight'] = [another,bunch,of,stuff]
a['two'] = [more,stuff]

but now variable 'a' contains

{eight: [a,bunch,of,stuff],first: [another,bunch,of,stuff],two: [more,stuff]}

while what I wanted was

{first: [another,bunch,of,stuff], eight: [a,bunch,of,stuff],two:[more,stuff]}

I'm guessing the order is based on the alphabetical order of the keys. This is a problem, because I want to display the data into hbs using {#each model as |key value|} in the same order as I wanted it.




Aucun commentaire:

Enregistrer un commentaire