How to extend an existing JavaScript array with another array, without creating a new array

后端 未结 16 2042
深忆病人
深忆病人 2020-11-22 07:38

There doesn\'t seem to be a way to extend an existing JavaScript array with another array, i.e. to emulate Python\'s extend method.

I want to achieve th

16条回答
  •  [愿得一人]
    2020-11-22 07:47

    If you want to use jQuery, there is $.merge()

    Example:

    a = [1, 2];
    b = [3, 4, 5];
    $.merge(a,b);
    

    Result: a = [1, 2, 3, 4, 5]

提交回复
热议问题