Home > OS >  ERROR: TypeError: Cannot read properties of undefined (reading 'indexOf')
ERROR: TypeError: Cannot read properties of undefined (reading 'indexOf')

Time:04-16

In this code, I have an error that says "Cannot read properties of undefined (reading 'indexOf')"

lowPassword(control: FormControl): {
  [lowLevelPassword: string]: boolean;
} {
  if (this.invalidPassword.indexOf(control.value) != -1) {
    return {
      lowLevelPassword: true,
    };
  }
  return null;
}

CodePudding user response:

invalidPassword is a array like => [{id: 1, name:'john'}] control.value is a key like => control.value = name

if there is name like key in invalidPassword array it return true otherwise false

Example:

(control.value in invalidPassword) ? 'available' : 'none'

  • Related