JS

HOW TO FLATTEN ARRAYS IN JAVASCRIPT

1) FLAT FUNCTION

NESTED ARRAY var arrA = [   "First",  ["Second", ["Third"]], "Forth"  ];   ["FIRST", "SECOND", "THIRD", "FORTH"] var arrB = arrA.flat(2);

2) ARRAY TO STRING

NESTED ARRAY var arrA = [   "First",  ["Second", ["Third"]], "Forth"  ];   "FIRST,SECOND,THIRD,FORTH" var arrB = arrA.toString();

3) ARRAY JOIN

NESTED ARRAY var arrA = [   "First",  ["Second", ["Third"]], "Forth"  ];   "FIRST-SECOND-THIRD-FORTH" var arrB = arrA.flat(2).join("-");