我有一个JavaScript数组,如:
[["$6"], ["$12"], ["$25"], ["$25"], ["$18"], ["$22"], ["$10"]]
Run Code Online (Sandbox Code Playgroud)
我将如何将单独的内部数组合并为:
["$6", "$12", "$25", ...]
Run Code Online (Sandbox Code Playgroud) 我想将2D JavaScript数组转换为1D数组,以便将2D数组的每个元素连接成单个1D数组.
在这里,我正在尝试转换arrToConvert为1D阵列.
var arrToConvert = [[0,0,1],[2,3,3],[4,4,5]];
console.log(get1DArray(arrToConvert)); //print the converted array
function get1DArray(2dArr){
//concatenate each element of the input into a 1D array, and return the output
//what would be the best way to implement this function?
}
Run Code Online (Sandbox Code Playgroud)