O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Combining Arrays

var fruits = ["banana", "apple", "orange"]; var veggies = ["broccoli", "carrots", "spinach"]; var grains = ["wheat", "oats"]; var food = grains.concat(fruits, veggies); //food = ["wheat","oats","broccoli","carrots", "spinach","banana","apple","orange"]

You can combine multiple arrays using the .concat(arr, arr, ...) method. This returns a new array object with the array elements combined inside.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required