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":"-"};

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.
LVL 16
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

leakim971Connect With a Mentor PluritechnicianCommented:
Test page :

var obj = {"O":"-","R":"-","L":"-","D":"-"};// YOUR LINE

var bck = obj;
obj = {};

obj.W="-";// YOUR LINE

for(var i in bck) obj[i] = bck[i];

alert(JSON.stringify(obj));// YOUR LINE

Open in new window

All Courses

From novice to tech pro — start learning today.