Initial PHP ARRAY Storing attributes as values and respective id's on key
Array
(
[979] => Pict Model
[962] => Brand
[494] => Dimensions
[980] => Capacity
[981] => Power
[982] => List Price
[983] => Warrenty
[975] => USB Connection
[976] => Self Cleaning
[977] => Double Glass Door
[978] => Steam Function
[974] => Electricity Type
)
In my Code below, comparable_attr holds the json encoded array. After that, as i console.log(comparable_attr) This gives me a json of order as of php array.
Then, after i parseJSON and then console.log it gave me data in different order.
var comparable_attr = '<?php echo json_encode($_comparable_attributes); ?>';
if(comparable_attr.length != 0){ //check for empty json
console.log(comparable_attr);
var obj = jQuery.parseJSON(comparable_attr);
console.log(obj);
}
Problem : i want to achieve it in same order after i parseJSON.
The result obtained :
First Console.log(comparable_attr) gives:
{"979":"Pict Model","962":"Brand","494":"Dimensions","980":"Capacity","981":"Power","982":"List Price","983":"Warrenty","975":"USB Connection","976":"Self Cleaning","977":"Double Glass Door","978":"Steam Function","974":"Electricity Type"}
Second Console.log(obj) gives :
Object { 494="Dimensions", 962="Brand", 974="Electricity Type", more...}
Edited :
What i have found is, it shorted according to my attribute id, which i need in the same order as it is in array.