Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
20
rated 0 times [  26] [ 6]  / answers: 1 / hits: 89354  / 14 Years ago, sun, january 30, 2011, 12:00:00

Is there a built in way to append one list into another like so:



var a = [1,2,3];
a.append([4,5]);
// now a is [1,2,3,4,5];


concat() does something similar but returns the result. I want something that modifies the existing list like push()


More From » javascript

 Answers
41

push will work, but you also need to use apply.



var a = [1,2,3];
a.push.apply(a, [4,5])

[#93988] Thursday, January 27, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
wyattkennyc

Total Points: 650
Total Questions: 102
Total Answers: 90

Location: Monaco
Member since Mon, May 23, 2022
2 Years ago
;