如何更改数组对象中的值?

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
猛跑小猪
浏览 2239回答 2
2回答

12345678_0001

不用第三方库也可以实现,比较简单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);

明月笑刀无情

for(vari=0;i
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript