concate js 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: concat js mdn

const array1 = ['a', 'b', 'c'];
const array2 = ['d', 'e', 'f'];
const array3 = array1.concat(array2);

console.log(array3);
// expected output: Array ["a", "b", "c", "d", "e", "f"]

Example 3: javascript concatenation

// the fastest way to string concat in cycle when number of string is less than 1e6
// see https://medium.com/@devchache/the-performance-of-javascript-string-concat-e52466ca2b3a
// see https://www.javaer101.com/en/article/2631962.html
function concat(arr) {
    let str = '';
    for (let i = 0; i < arr.length; i++) {
        str += arr[i];
    }

    return str;
}