javaScript object doesn't keep key order giving from php -
i have array use json_encode
on looks in php
array ( [4] => array ( [numberof] => 60 [date] => 4 ) [3] => array ( [numberof] => 3 [date] => 3 ) [2] => array ( [numberof] => 6 [date] => 2 ) [1] => array ( [numberof] => 5 [date] => 1 ) [12] => array ( [numberof] => 1 [date] => 12 ) [11] => array ( [numberof] => 0 [date] => 11 ) )
however, when accessing via javascript
the order following
{ "1":{"numberof":5,"date":"1"}, "2":{"numberof":6,"date":"2"}, "3":{"numberof":3,"date":"3"}, "4":{"numberof":60,"date":"4"}, "11":{"numberof":0,"date":"11"}, "12":{"numberof":1,"date":"12"} }
how can keep order set in php.
javascript objects not ordered.
ecma 5.1 section 4.3.3 (doesn't guarantee order)
an object collection of properties , has single prototype object. prototype may null value.
ecma 3rd edition section 4.3.3 (explicitly says not ordered)
an object member of type object. unordered collection of properties each of contains primitive value, object, or function. function stored in property of object called method.
even javascript "associative array" (which collection of named properties in object) can't guarantee order.
Comments
Post a Comment