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

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

 更新時(shí)間:2022年09月01日 10:29:09   作者:愛(ài)編譯也愛(ài)吃肉的喵  
這篇文章主要介紹了如何從對(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é)果如下: 

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

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

相關(guān)文章

最新評(píng)論

大埔区| 兴国县| 蕲春县| 梁河县| 曲麻莱县| 沈丘县| 石狮市| 荔浦县| 江津市| 德化县| 文安县| 甘德县| 师宗县| 潼南县| 邵武市| 监利县| 黄浦区| 大荔县| 稻城县| 社旗县| 赞皇县| 广元市| 襄垣县| 宝兴县| 琼结县| 寿宁县| 东丽区| 甘泉县| 辽源市| 洛阳市| 渭南市| 邻水| 邢台市| 临沂市| 斗六市| 恩施市| 永定县| 溆浦县| 仁怀市| 陵川县| 克东县|