JavaScript: How to join / combine two arrays to concatenate into one array? [duplicate]

JavaScript: How to join / combine two arrays to concatenate into one array? [duplicate]

This question already has an answer here:

How to merge two arrays in JavaScript and de-duplicate items

72 answers

I’m trying to combine 2 arrays in javascript into one.
var lines = new Array(“a”,”b”,”c”);
lines = new Array(“d”,”e”,”f”);

This is a quick example, i want to be able to combine them so that when the second line is read the 4th element in the array would return “d”
How would i do this?

Solutions/Answers:

Solution 1:

var a = ['a','b','c'];
var b = ['d','e','f'];
var c = a.concat(b); //c is now an an array with: ['a','b','c','d','e','f']
console.log( c[3] ); //c[3] will be 'd'

Related:  Socket.io Client: respond to all events with one handler?