//一维数组var arr = new Array("1","5","3"),
//二维数组,var arr = new Array(['1','2'],['3','4'])。还可以这样
//var arr=[1,2,3,4,5,6,7,8,9]
arr[0] = 1arr[2] = 5arr[3] = 3//进行赋值
for(var i = 0i <arr.length - 1i++) {//进行从大到小的排序
for(var j = 1j <arr.lengthj++) {
if(arr[i] <arr[j]) {
var temp = arr[i]
arr[i] = arr[j]
arr[j] = temp
}
}
}
alert(arr.join("<"))//提示框中提示arr数组中的所有项且把没个元素用‘<’链接起来的字符
//串,其结果为:5<3<1。join(str)函数是把数组中的元素用str连接起来成
//字符串
let arr = [{DyeWorkQtyA:"DyeWorkQtyA" ,
DyeWorkQtyB: "DyeWorkQtyB",
EmpNameA: "EmpNameA",
EmpNameB: "EmpNameB",
LingBanA: "LingBanA",
LingBanB: "LingBanB",
MachineName: "MachineName",
MonthWorkQtyA: "MonthWorkQtyA",
MonthWorkQtyB: "MonthWorkQtyB",
ShiftNameA: "ShiftNameA",
ShiftNameB: "ShiftNameB",
firstColumn: "firstColumn",
}]
let arrs = arr[0]
let third = []
let arr1 = []
let rows = []
for(let i in arrs){
let col = i.substring(0, (i.length -1))
let last = i.substr(-1)
let ins = false
for(let j in rows){
if(rows[j] == col){
ins = true
break
}
}
if(!ins &&(last == 'A' || last == 'B')){
rows.push(col)
}
}
for(let row in rows){
let temp = []
for(let key in arrs){
let last = key.substr(-1)
if(key.indexOf(rows[row]) != -1){
temp.push({[last]: arrs[key]})
}
}
third.push(temp)
}
for(let key in arrs){
let first = key.substr(0, 1)
let last = key.substr(-1)
if(last != 'A' &&last != 'B' &&/[A-Z]/.test(first)){
arr1.push({[key]: ''})
}
}
arr1.push({'thirdColumn': third})
console.log(JSON.stringify(arr1))
这个需要你在输出的时候加上'[ ]'符号的,遍历输出的时候加上<script>
var arr = [[1,2,3],[4,5,6]]
document.write('[')
for( var i = 0 i <arr.length i ++){
document.write(' [ ')
for(var j = 0 j <arr[i].length j++){
document.write(arr[i][j])
}
if(i !=arr.length-1){
document.write(' ] , ')
}else{
document.write(' ] ')
}
}
document.write(' ] ')
</script>