The flat() method of an array creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.

    
    const numbers = [0, 1, 2, [3, 4]];

    const flatten1 = numbers.flat();

    console.log(flatten1);
    // [0, 1, 2, 3, 4]

    const numbers1 = [0, 1, [2, [3, [4, 5]]]];

    const flatten2 = numbers1.flat();

    console.log(flatten2);
    // [0, 1, 2, Array [3, Array [4, 5]]]

    const flatten3 = numbers1.flat(3);

    console.log(flatten3);
    // [0, 1, 2, 3, 4, 5]