When passing an array as a parameter to a function, I aim to retrieve its length.
Within my code, I am working with an array of objects.
groupList:group[]=[];
Within the selectItem
function, I invoke the 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
}
}
}
However, I encounter an error message indicating an undefined length.
TypeError: Cannot read property 'length' of undefined