Flasj q: Arrays
- Started
- Last post
- 8 Responses
- Fariska
I'm having some issues with arrays:
I have an array, named "objects",
i assign it to another variable, named objects2 (var objects2 = objects)
then i sort objects2 with a function i defined (objects2.sort (mySortingFunc) )
and, here comes the problem.
doing a trace, objects2 appears to be properly sorted, BUT if I trace the original array "objects" it is ordered in the same way as "objects2".I think the cause is that i passed to objects2 the reference and not the content of the "objects" array. Is there a way to "duplicate" the content of an array, cause i need them separated?
- UndoUndo0
did you define objects2 as a new Array.
ie
objects2 = Array();
objects2 = objects;that might help
- Fariska0
Tried, but same result :-/
- UndoUndo0
so when you modify objects2, objects is also modified?
- Fariska0
exactly. Now i'm triyng to write a duplicate method for the prototype object.
- UndoUndo0
why dont you just loop through the first array and push the contents into the second one using array.push()
- Fariska0
Many thanks guys.
I was working on something similar.
- Fariska0
Works!!!! Great
*offers a pint