yossi yossi - 1 month ago 13
jQuery Question

jQuery $.extend - to extend an Array

Using the

$.extend
is working, but it returns an Object and not a native Array, so the
push()
won't work.

How can I extend an array, using the
jQuery.extend
?

var x =[1,2];
var y = $.extend({},x);
y.push(3) // fail




edit:
The array WILL contain objects, so - the
slice()
won't do the trick

Answer

No need of jQuery at all use Array#concat method.

var x =[1,2];
var y = x.concat([3,4]);
y.push(3)