码迷,mamicode.com
首页 > 编程语言 > 详细

数组替换成一个新数组

时间:2019-09-05 01:02:48      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:length   turn   users   log   console   user   ===   for   替换   

if(this.goldUsers[i].label.length>1){
let a = this.goldUsers[i].label
a [20001, 20004]
let c = {
20001:‘大理石‘,
20002:‘人造石‘,
20003:‘石英石‘,
20004:‘花岗石‘,
}
let b = a.map(item=>{
return c[item]
})
console.log(b)
b ["大理石", "花岗石"]
// 第一中
// let b = a.map(item=>{
// if(item === 20001){
// return ‘大理石‘
// }else if(item === 20002){
// return ‘人造石‘
// }else if(item === 20003){
// return ‘石英石‘
// }else if(item === 20004){
// return ‘花岗石‘
// }
// })
// console.log(11,b)
// 第二中
// for(let j = 0;j < a.length;j++){
// if(a[j] == 20001){
// a[j] = ‘大理石‘
// }else if(a[j] == 20002){
// a[j] = ‘人造石‘
// }else if(a[j] == 20003){
// a[j] = ‘石英石‘
// }else if(a[j] == 20004){
// a[j] = ‘花岗石‘
// }
// console.log(3,a[j])
//
// }
// console.log(34,this.goldUsers[i].label)
this.goldUsers[i].label = b
}

数组替换成一个新数组

标签:length   turn   users   log   console   user   ===   for   替换   

原文地址:https://www.cnblogs.com/isuansuan/p/11462630.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!