add two arrays together code example
Example 1: combine two arrays javascript
let arr1 = [0, 1, 2];
let arr2 = [3, 5, 7];
let primes = arr1.concat(arr2);
// > [0, 1, 2, 3, 5, 7]
Example 2: javascript concat two arrays
//ES6
const array3 = [...array1, ...array2];
Example 3: concatenate multiple arrays javascript
const array1 = ['a', 'b', 'c'];
const array2 = ['d', 'e', 'f'];
const array3 = [...array1, ...array2];
console.log(array3);
// expected output: Array ["a", "b", "c", "d", "e", "f"]
Example 4: addition of two arrays
int[] a = {10, 20 30, 40}; int[] b = {25, 50, 75, 100, 125}; int[] sum = new int[b.length]; for (int i = 0; i <= b.length; i++){ sum[i] = 0; /*initialize each of the sum values as zeroes, because that's what we usually start with*/ if (i > b.length){ /*if one array is longer than the other, just add zero the remaining elements in the largest array*/ sum[i] = b[i] + 0; else{ sum[i] = a[i] + b[i]; } }