Filter list based on Array value

Hi guys. Probably I’m missing something here. The script above works perfectly in the case of a pure string. What I am trying to achieve now is doing the same, but this time check an Array. The list is actually a list of favorites where you find the Array with users uid.

favorites [{“uid":"jTIXVM2nCjVGuih99LJToS2zSZ43”}]

However, something is going wrong and what I see as a result is TypeError: Cannot read property ‘includes’ of undefined. And of course, nothing listed.
I tried
let favorite = JSON.stringify(this.props.likes) and then

let filteredItems = [];
items.forEach(item => {
if (item[favorites].includes(this.props.appActions.dataSlots[‘ds_SlotUserID’])) {
filteredItems.push(item);
}
});
items=filteredItems;
return items;

//

Can you guys please help me here finding the right way to do this?

Best Regards, Marcos

The error message means that item[favorites] is giving you ‘undefined’ thus includes method can’t be called. What values the favorites variable should have? Looks like it’s causing some problems.

Hi Juha, thanks for your quick reply. The value have the user uid inside an Array that looks likes this: note: The includes method works fine if is not an Array/object. I tried so many ways and just couldn’t find a way the problem supposedly easy to be solve. Thanks for your help.

[{“uid":"jTIXVM2nCjVGuih99LJToS2zSZ43”}]

This issue is solved like this using the template

const db = firebase.firestore();
let ThreadId = this.props.appActions.dataSlots[‘ds_SlotThreadID’]
const ref = db.collection(‘Threads’).doc(ThreadId).collection(‘Proposals’)
.where(‘likes’, ‘array-contains’, {“uid”: uid})

thanks anyway

1 Like