Is there a method to clone an array in jQuery?

zjm1126 picture zjm1126 · Sep 23, 2010 · Viewed 76.4k times · Source

This is my code :

var a=[1,2,3]
b=$.clone(a)
alert(b)

Doesn't jQuery have a 'clone' method? How can I clone an array using jQuery?

Answer

meder omuraliev picture meder omuraliev · Sep 23, 2010

Just use Array.prototype.slice.

a = [1];
b = a.slice();

JSFiddle - http://jsfiddle.net/neoswf/ebuk5/