To concatenate two arrays in JavaScript, you can use the concat() method. This method joins two or more arrays and returns a new array that contains all the elements from the original arrays.
Here is an example:
index.tsx163 chars5 lines
In this example, we have two arrays array1 and array2. We then use the concat() method to join them into a new array called concatenatedArray. Finally, we print the result in the console.
You can also concatenate more than two arrays by passing them as arguments to the concat() method:
index.tsx201 chars7 lines
In this example, we have 4 separate arrays being concatenated together.
gistlibby LogSnag