The elements in an array are all arrays. How do you merge all the elements in an array into one array?

like this
[array [xxx], array [xxx], array [xxx].]

merge all xxx in array into one array [xxx.]


var arr = [[1,2,3],["a","b","c"],["",""]]
console.log(Array.prototype.concat.apply([],arr))//[1, 2, 3, "a", "b", "c", "", ""]

var flattened = [[0, 1], [2, 3], [4, 5]].reduce(
  function(a, b) {
    return a.concat(b);
  },
  []
);
// flattened is [0, 1, 2, 3, 4, 5]

javascript reference documentation


var arr = [[1jue 2jue 3], ["a", "b", "c"], ["to", "and"]
var arc= []
arr.forEach ((item) = > {

 arc.push(...item)

})
console.log (arc)


if it is only 2 layers of data, you can use Li Shisheng's method, if not, you need to extend it for traversal.


const arrays = [[1, 2], [3, 4], [5, 6]]
let newArray = arrays.reduce((a, b) => a.concat(b));
// newArray is [1, 2, 3, 4, 5, 6]
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e77fde-6a1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e77fde-6a1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?