I have this code:
//...
let kozvetlenFl = []
if (kozvetlenFl.length === 0 || kozvetlenFl.findIndex(feladat => feladat.id === child) === -1) {
kozvetlenFl.push(
feladatok.find(feladat => child === feladat.id)
)
}
//...
What i want to earn with this code is to check if the kozvetlenFl
is empty (because first, it is), or if it isn't empty, check for duplicate (the child here is not relevant). If i set OR in an if statement, it checks all the statements, or if the first is true, it executes? Because i get the error: TypeError: Cannot read property 'id' of undefined
. Because the kozvetlenFl
first is empty. How to solve this problem?