|
copycopy Nested Structures / Objects in JavascriptHi I'm trying to copy a nested structure in the Javascript patch so i can manipulate it. The function i came up with does work, but it messes up the order of the structure. function cloneObject(oldObject) { var newObject = new Object() for (i in oldObject) { if (typeof oldObject[i] == 'object') { newObject[i] = new cloneObject(oldObject[i]); } else newObject[i] = oldObject[i]; } return newObject } Anyone has a suggestion? i'm kinda at the end of my javascript knowledge here. thanx
|