JRS: In article <708430f3.0309220622.327c20bd (AT) posting (DOT) google.com>, seen
in news:comp.lang.javascript, John Geddes <john (AT) starmarkassociates (DOT) co.uk
Quote:
posted at Mon, 22 Sep 2003 07:22:35 :-
Any neat way to copy a snapshot of one array to another? |
A = [1, 2, 3]
C = [].concat(A)
C[1] = 4
x = [A, ' ', C] ; alert(x) // 1,2,3, ,1,4,3
But note
A = [1, 2, [5,6,7]]
C = [].concat(A)
C[1] = 4 ; C[2][1] = 9 // 1,2,5,9,7, ,1,4,5,9,7
though
A = [1, 2, [5,6,7]]
C = [].concat(A)
C[1] = 4 ; C[2] = 8 // 1,2,5,6,7, ,1,4,8
The "top level" of A is copied, but not lower levels.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.