Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

JavaScript: Add item to BEGINNING of object (NOT ARRAY)

How can I add an item to the beginning of an object?  This adds it to the end:
var obj = {"O":"-","R":"-","L":"-","D":"-"};
obj.W="-";
alert(JSON.stringify(obj));

Open in new window

I was advised to use unshift() however that seems to only work with arrays.  This must stay an object, and the desired order must be maintained.
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial