var arrT = ["249,胡皓杨", "287,小小", "256,涂子航", "263,胡熠宸", "169,小丽丽", "199,裴宗硕", "270,李二狗", "245,王嘉沐", "282,崔一一", "252,刘哲瀚", "291,易建联", "259,丁紫依", "175,邓颐雪", "266,方悦溪", "212,王五博", "278,吃多多", "248,周歆悦", "286,王思聪", "255,胡若凌", "262,王为灏", "168,王二", "198,兜兜兜", "269,丁舒宇", "244,易小乐", "281,丁玉函", "251,宋文蕊", "290,黄蓉", "258,张晟宇", "265,胡菁", "172,覃冉尔", "206,李小杨", "274,李宇涵孩子", "247,胡义豪", "285,王小小", "254,吴欣平", "261,胡芮诚", "195,章蔚青", "268,程烨堃", "243,马梦琪", "280,丁子怡", "250,覃冉尔", "289,郭靖", "257,胡耀宇", "264,叶恩哲", "171,丁紫依", "201,李飒", "272,22", "246,徐铭鸿", "284,李小小", "253,应尚洋"]
1: var arrT2 = []
for (var i = 0; i < arrT.length; i++) {
arrT2.push(arrT[i].split(',')[0])
}
console.log(arrT2);
2:var arrT2 = []
arrT2 = arrT.map(item => item.split(',')[0] )
二、数组中元素添加id
const selectStudent = [... this.userNameList]
const Student = []
for(var key in selectStudent) {
let obj = new Object();
console.log("kkk",selectStudent[key]);
obj.stuId = selectStudent[key]
Student.push(obj)
}
console.log("sss",[... Student]);
//穿梭框提交学生
submitAdd: function(){
console.log("学生",this.userIdList);
const selectStudent = this.userIdList.map(item =>item.split(',')[0])
console.log(666,selectStudent);
let obj1 = Object.assign({},this.userIdList)
let resultArr = [];
for( var key in obj1){
let obj = new Object();
obj.id = obj1[key].split(',')[0]
obj.name = obj1[key].split(',')[1]
resultArr.push(obj)
}
resultArr.forEach((item) =>{
console.log(1244,item.id);
this.selectStudent.push(item.id)
})
console.log(99999,this.selectStudent);
return selectStudent.forEach((item)=>{
console.log(78,item[0]);
})
},
11:给数组中元素添加id与name
let list = ['31,王小明','1000,八重樱','200,卡莲'];
let obj1 = Object.assign({},list)
console.log(obj1)
let resultArr = [];
for( var key in obj1){
let obj = new Object();
obj.age = obj1[key].split(',')[0]
obj.name = obj1[key].split(',')[1]
obj.id = 'id' + new Date().getTime();
resultArr.push(obj)
}
console.log(resultArr);
22:
let list = ['31,王小明','1000,八重樱','200,卡莲'];
let obj1 = Object.assign({},list)
console.log(obj1)
let resultArr = [];
for( var key in obj1){
let obj = new Object();
obj.age = obj1[key].split(',')[0]
obj.name = obj1[key].split(',')[1]
resultArr.push(obj)
}
console.log(resultArr);