varstooges=[{label:1,value:1,placeCode:'sh',stock_code:40},{label:1,value:1,placeCode:'sh',stock_code:50},{label:1,value:1,placeCode:'sz',stock_code:60,status:1},{label:1,value:1,placeCode:'sz',stock_code:39,status:1}];我想将上面代码里的placeCode改变值:"sh"改为"沪","sz"改为"深",请问如何操作,最好用underscore.js或lodash.js
2 回答
12345678_0001
TA贡献1802条经验 获得超5个赞
不用第三方库也可以实现,比较简单varstooges=[{label:1,value:1,placeCode:'sh',stock_code:40},{label:1,value:1,placeCode:'sh',stock_code:50},{label:1,value:1,placeCode:'sz',stock_code:60,status:1},{label:1,value:1,placeCode:'sz',stock_code:39,status:1}];varmaps=newMap([['sh','沪'],['sz','深圳']]);stooges=stooges.map(element=>{element.placeCode=maps.get(element.placeCode);returnelement;});console.log(stooges);
明月笑刀无情
TA贡献1828条经验 获得超4个赞
for(vari=0;istooges[i].placeCode==='sh'?stooges[i].placeCode='沪':stooges[i].placeCode='深' }一个循环就搞定为啥用库来?
添加回答
举报
0/150
提交
取消