第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

js 怎么將數(shù)組按照一定條件分組

js 怎么將數(shù)組按照一定條件分組

素胚勾勒不出你 2019-05-11 09:34:08
得到數(shù)組:this.dataBarrage=res.listlist:[0:{id:"1",content:"ddddd",percent:"60"}1:{id:"1",content:"ddddd",percent:"30"}2:{id:"2",content:"葫蘆娃",percent:"0"}3:{id:"3",content:"本領(lǐng)大",percent:"10"}4:{id:"4",content:"Qwery",percent:"0"}比如我在界面上獲取的一個(gè)高度值為20,那么我怎么獲取這個(gè)數(shù)組里面percent的值為10-30范圍的值,就是我要根據(jù)我的高度將這個(gè)數(shù)組分組。這個(gè)高度值已經(jīng)獲取為this.scrollStop。怎么根據(jù)這個(gè)高度值計(jì)算this.scrollStop-10到this.scrollStop+10得到這個(gè)范圍里面的數(shù)組?
查看完整描述

2 回答

?
繁星coding

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超4個(gè)贊

遍歷這個(gè)對(duì)象數(shù)組,用array.filter就可以了
letlist=[
{id:"1",content:"ddddd",percent:"60"},
{id:"1",content:"ddddd",percent:"30"},
{id:"2",content:"葫蘆娃",percent:"0"},
{id:"3",content:"本領(lǐng)大",percent:"10"},
{id:"4",content:"Qwery",percent:"0"},
]
letheight=20
list=list.filter(e=>{
returnparseInt(e.percent)<=(height+10)&&parseInt(e.percent)>=(height-10)
})
console.log(list)
                            
查看完整回答
反對(duì) 回復(fù) 2019-05-11
?
ibeautiful

TA貢獻(xiàn)1993條經(jīng)驗(yàn) 獲得超6個(gè)贊

varlist=[{id:"1",content:"ddddd",percent:"60"},
{id:"1",content:"ddddd",percent:"30"},
{id:"2",content:"葫蘆娃",percent:"0"},
{id:"3",content:"本領(lǐng)大",percent:"10"},
{id:"4",content:"Qwery",percent:"0"},
{id:"5",content:"ddddd",percent:"80"},
{id:"6",content:"ddddd",percent:"90"},
{id:"7",content:"ddddd",percent:"50"},
]
functionsearch(data,key,offset,val){
varnewArr=[];
for(vari=0;ivark=parseInt(data[i][key]);
if(val>=(k-offset)&&val<=(k+offset))
newArr.push(data[i]);
}
returnnewArr;
}
search(list,'percent',10,20);//數(shù)據(jù)字段偏差范圍給出的值
                            
查看完整回答
反對(duì) 回復(fù) 2019-05-11
  • 2 回答
  • 0 關(guān)注
  • 2855 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)