The x.name and imgname have the same type (string) and the same value "comcardpro_capsule_model_2". But why the findIndex() function return -1? Please explain it to me.
findPicture(imgname): number {
return this.info.comcardList.findIndex(x => {
x.name === imgname; // result in console:
console.log(imgname) // comcardpro_capsule_model_2
console.log(typeof imgname) // string
console.log(typeof x.name) // string
console.log(x.name); // comcardpro_capsule_model_2
})
}
Expect result will be index of the element in array not -1.
returningthe result of the comparison. That's all that's going on here.