Use the concat function, like so:
var arrayA = [1, 2]; var arrayB = [3, 4]; var newArray = arrayA.concat(arrayB);
The value of
newArray will be
[1, 2, 3, 4] (
arrayB remain unchanged;
concat creates and returns a new array for the result).
More Related Contents:
- Does an array contain a specific item? [duplicate]
- How to delete an item from state array?
- Create an array with same element repeated multiple times
- How can I split a string into segments of n characters?
- adding custom functions into Array.prototype
- Sorting on a custom order
- How do I extract even elements of an Array?
- Array map function doesn’t change elements
- Replace element at specific position in an array without mutating it
- push() a two-dimensional array
- TypeScript enum to object array
- Using lodash to compare jagged arrays (items existence without order)
- best way to generate empty 2D array
- Access object property in array of objects
- Find last index of element inside array by certain condition
- How to flatten array in jQuery?