最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

如何從對(duì)象數(shù)組中篩選符合條件的值

 更新時(shí)間:2022年09月01日 10:29:09   作者:愛編譯也愛吃肉的喵  
這篇文章主要介紹了如何從對(duì)象數(shù)組中篩選符合條件的值,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。

從對(duì)象數(shù)組中篩選符合條件的值

const arr = [1,2,3,4,5,6,7]
const list = [
	{openId: 1, timelineId: 1, showNo: 1, uid: 1},
	{openId: 2, timelineId: 1, showNo: 1, uid: 1},
	{openId: 9, timelineId: 1, showNo: 1, uid: 1},
	{openId: 4, timelineId: 1, showNo: 1, uid: 1},
	{openId: 5, timelineId: 1, showNo: 1, uid: 1}
]
const params = list.filter(item=> arr.indexOf(item.openId) > -1)
console.log(params)

將兩個(gè)對(duì)象數(shù)組根據(jù)相同的索引index合并為一個(gè)數(shù)組

this.currentTotalList = this.totalList.map((item, index) => ({ ...item, ...daysList[index] }))

將兩個(gè)對(duì)象數(shù)組根據(jù)相同的鍵值合并為一個(gè)數(shù)組

let currentEveryList = this.everyList.map(item => ({...item, ...signList.filter(s => s.signDate === item.signDate)[0]}))

從當(dāng)前數(shù)組中篩選符合條件的值

this.materialss = this.materials.filter(item => item.categoryId === this.curTab.categoryId)

js根據(jù)已有數(shù)組,從數(shù)組對(duì)象中篩選數(shù)據(jù)

例如,已得到以下源數(shù)據(jù)

? ? ? ? let dataArr = [
? ? ? ? ? ? { id: 1, age: 15 },
? ? ? ? ? ? { id: 2, age: 18 },
? ? ? ? ? ? { id: 3, age: 16 },
? ? ? ? ? ? { id: 4, age: 17 }
? ? ? ? ];

現(xiàn)在需要跟據(jù)獲取的id數(shù)組(表格選中的行),篩選源數(shù)據(jù)

let goalArr = [1, 2];

解決思路

<script>
? ? ? ? let dataArr = [
? ? ? ? ? ? { id: 1, age: 15 },
? ? ? ? ? ? { id: 2, age: 18 },
? ? ? ? ? ? { id: 3, age: 16 },
? ? ? ? ? ? { id: 4, age: 17 }
? ? ? ? ];
? ? ? ? let goalArr = [1, 2];
? ? ? ? let resArr = [];
? ? ? ? goalArr.forEach((v, i) => {
? ? ? ? ? ? dataArr.forEach((item, index) => {
? ? ? ? ? ? ? ? if (item.id === v) {
? ? ? ? ? ? ? ? ? ? resArr.push(item)
? ? ? ? ? ? ? ? }
? ? ? ? ? ? })
? ? ? ? })
? ? ? ? console.log(resArr)
//
</script>

打印結(jié)果如下: 

本來想用filter加forEach實(shí)現(xiàn)的,思路有點(diǎn)混亂爛尾了

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

湟中县| 香格里拉县| 大洼县| 白城市| 安西县| 土默特左旗| 古丈县| 揭西县| 师宗县| 雷山县| 安塞县| 鹤庆县| 丰顺县| 沂水县| 外汇| 彭州市| 平武县| 栖霞市| 屏南县| 富锦市| 庆城县| 钟祥市| 和田市| 新干县| 清徐县| 石首市| 元江| 南宁市| 伊通| 雷州市| 伊宁市| 漠河县| 崇信县| 铅山县| 云龙县| 孝义市| 上蔡县| 习水县| 阜新| 策勒县| 温泉县|