创建一个数组
var arr = [['a', 'b', 'c'], ['d', 'e', 'f'], [1, 2, 3, 'a', 'f']]
二维数组转一维数组
function ArrayFn(arr) {
var brr = []
for (var i = 0; i < arr.length; i++) {
brr = brr.concat(arr[i])
}
return brr
}
console.log(ArrayFn(arr))//['a', 'b', 'c', 'd', 'e', 'f', 1, 2, 3, 'a', 'f']
二维数组转一维数组并去重
function ArrayFn2(arr) {
var brr = []
var crr = []
for (var i = 0; i < arr.length; i++) {
var crr = arr[i]
for (var j = 0; j < crr.length; j++) {
if (brr.indexOf(crr[j])==-1) {
brr.push(crr[j])
}
}
}
return brr
}
console.log(ArrayFn2(arr))//['a', 'b', 'c', 'd', 'e', 'f', 1, 2, 3]
标签:crr,arr,数组,++,brr,二维,一维,var
From: https://blog.csdn.net/Ljt99/article/details/140468812