有兩組數(shù)組arr01和arr02現(xiàn)在下把a(bǔ)rr01數(shù)組中的某個(gè)字段添加到arr02中,現(xiàn)在問(wèn)題是最后得到的新數(shù)組總是arr01的最后一個(gè)字段letarr01=[{"account":"000000000000"},{"account":"111111111111"},{"account":"2222222222222"}];letarr02=[{"city":"北京"},{"city":"上海"},{"city":"廣東"}];letnewArr=[];arr01.map((cur01,eq)=>{arr01.map((cur02,index)=>{cur02.account=cur01.account;returnnewArr.push(cur);})})最后結(jié)果:newArr=[{"account":"2222222222222","city":"北京"},{"account":"2222222222222","city":"上海"},{"account":"2222222222222","city":"廣東"},{"account":"2222222222222","city":"北京"},{"account":"2222222222222","city":"上海"},{"account":"2222222222222","city":"廣東"},{"account":"2222222222222","city":"北京"},{"account":"2222222222222","city":"上海"},{"account":"2222222222222","city":"廣東"}];我想得到的結(jié)果是:newArr=[{"account":"000000000000","city":"北京"},{"account":"000000000000","city":"上海"},{"account":"000000000000","city":"廣東"},{"account":"111111111111","city":"北京"},{"account":"111111111111","city":"上海"},{"account":"111111111111","city":"廣東"},{"account":"2222222222222","city":"北京"},{"account":"2222222222222","city":"上海"},{"account":"2222222222222","city":"廣東"}];
map循環(huán)嵌套,總是取得外層數(shù)組的最后一個(gè)值
繁華開(kāi)滿天機(jī)
2019-05-21 09:25:41