Basically in my react app I want to filter an array that meets 3 conditions, but if I use && (and) two times it doesn't work, only if I use || (or) and && (and) together.
Example of data:
// url /practice/${tName}/${level}/play/${nextPage}
// this case url - /practice/Animals/1/play/1
const { name: tName, pageNumber, box, level } = useParams();
const userInfo = [{
_id: '660dc1cbb2ac9d1ad31b59b2'
},{
_id: '660dc1cbb2ac9d1ad31b59b3'
}]
const initialTasks = [{
class: 'Animals',
level: 1,
rank: 1,
nr: 1,
part1: 'animals task 1 level 1 user 1',
user: '660dc1cbb2ac9d1ad31b59b2'
},
{
class: 'Animals',
level: 1,
rank: 1,
nr: 2,
part1: 'animals task 2 level 1 user 1',
user: '660dc1cbb2ac9d1ad31b59b2'
},
{
class: 'Animals',
level: 2,
rank: 1,
nr: 3,
part1: 'animals task 3 level 2 user 1',
user: '660dc1cbb2ac9d1ad31b59b2'
},
{
class: 'Animals',
level: 1,
rank: 1,
nr: 1,
part1: 'animals task 1 level 1 user 2',
user: '660dc1cbb2ac9d1ad31b59b3'
},
{
class: 'Hotel',
level: 1,
rank: 1,
nr: 1,
part1: 'hotel task 1 level 1 user 1',
user: '660dc1cbb2ac9d1ad31b59b2'
},
Why this code doesn't work? const tasksFiltered = initalTasks.filter(t => t.class === tName && t.level === level && t.user === userInfo._id);
But this one works? const tasksFiltered = initialTasks.filter(t => t.class === tName || t.level === level && t.user === userInfo._id);
I thought || (or) means that just one condition has to be true and the other one can be false...
My objective is when each user is on this page, the filter returns only the tasks that corrrespond to the url params.
PS: This is a simplified example, this data is being fetched trough redux from the database.