I would get a length of an array that I pass in the parameter of a function
I have an array of object
groupList:group[]=[];
in selectItem I call testExistinginArray function
selectItem (event) {
if(!this.toggle) {
this.groupList.push(event);
}
else{
this.ejList.push(event);
if(!this.testExistinginArray(event,this.groupList)) { //I pass groupList as parameter
this.groupList.push({code:event.codeBusinessGroup,name:event.nameBusinessGroup})
}
}
}
testExistinginArray(event,type: any[]) {
for(let i=0;i<this.type.length;i++) {
if (this.type[i].code.indexOf(event.codeBusinessGroup)===-1) {
return false
}
else{
return true
}
}
}
Actually I get undefined length error
TypeError: Cannot read property 'length' of undefined
selectItemcalled ?type.lengthinstead ofthis.type.length. Heretypeis not function variable, it's argument variable. So you can't read usingthisthisafter changing var. you can put it as an answer I'll accept it