javascript - JS one-liner filter similar objects from 2 arrays -
i'm trying filter 2 arrays have similar objects.
genrefiltered
returns correctly
sortfiltrered
should return aray 5 objects recommended
array.
instead returns empty.
can spot what i'm doing wrong way i'm filtering 2 arrays in sortfiltrered
?
let genrefiltered = genrevalue !== 15 ? games.filter((game) => game.genre_id === genrevalue) : games let sortfiltrered= sortvalue !== 1 ? genrefiltered.filter((game) => game.game_id === recommended.filter((rec) => rec.game_id)) : genrefiltered console.log('recommended', recommended) console.log('genrefiltered', genrefiltered) console.log('sortfiltrered', sortfiltrered)
output:
it can't equal ... should @ least first element.
let agefiltrered = sortvalue !== 1 ? genrefiltered.filter((game) => game.game_id === recommended.filter((rec) => rec.game_id)[0].game_id)
that code filter have game_id, , check first ocurrence.
if want not check first occurence can (it simple example can use in case):
var arr = [{w:'2'}, {w:'3'}, {w:'12'}, {w:'456'}] arr.filter(w => w.w.indexof(arr.filter(w => w.w === '22').map(w => w.w).join()) !== -1)
Comments
Post a Comment