In my Javascript application, I have an array with few properties var sampleArray = ["Number_Info", "Additional_Ids","Additional_Ids_2","_summary"];
Now I need to convert this array into an object containing properties in the same order, as shown below :
var sampleObject = {
"Number_Info" : {},
"Additional_Ids" : {},
"Additional_Ids_2" : {},
"_summary" : {}
}
I tried the following :
var orderingObj = {};
for(var i=0; i < sampleArray.length; i++ ){
orderingObj[sampleArray[i]] = {}
}
But here I am getting object properties in different order.
var orderingObj = {
"Additional_Ids_2" : {},
"Additional_Ids" : {},
"Number_Info" : {},
"_summary" : {}
};
How can I fix it? From earlier posts the solutions were there to sort by names but here I have a specific order in which I want to order my properties.