Hello guys i’ve tried to filter like this for result like this using filter and includes.. but not work, any solution using includes or something?
companies ids [1,2,3] user companies ids [1,2] filtered result [1,2]
i’ve tried like these
this.company.filter(company => company.id.includes(this.reviewerData.company_ids))
but output justlike []
thanks guys
Advertisement
Answer
let companiesids = [1,2,3]; let userids = [1,2]; let results = companiesids.filter(f => userids.indexOf(f) > -1); console.log(results);
UPDATED:
let companiesids = [{id: 1, name: 'a'},{id: 2, name: 'b'},{id: 3, name: 'c'}]; let userids = [1,2]; let results = companiesids.filter(f => userids.indexOf(f.id) > -1); console.clear(); console.log(results);