This is the structure of my arrays:-
projects
array:-
let projects = [
{
id: 1,
name: 'Project 1',
techs: [
id: 1
name: 'Tech 1'
]
},
{
id: 2,
name: 'Project 2',
techs: [
id: 1
name: 'Tech 2'
]
},
{
id: 3,
name: 'Project 3',
techs: [
id: 1
name: 'Tech 3'
]
},
{
id: 4,
name: 'Project 4',
techs: [
id: 1
name: 'Tech 1'
]
}
]
Right now I'm able to get only filtered projects of just Tech 1 as shown below:-
let filteredProjs = projects.filter(proj => proj.techs.some(tech => tech.name === 'Tech 1'))
I want to get filtered projects of Tech name = 'Tech 1' & 'Tech 2'. But it return
me nothing when I did as shown below:-
let filteredProjs = projects.filter(proj => proj.techs.some(tech => tech.name === 'Tech 1' && tech.name === 'Tech 2'))
How can I do this?
You might need to try OR operator (||
) instead of AND (&&
).
In Computer Programming, AND
returns true
only when conditions on both the sides evaluates to true
.
In case of OR
, it evaluates to true
if either of the conditions on any side returns true
.
In your case I assume you want to filter out projects in which Tech name equals 'Tech 1' OR
'Tech 2'.