我正在使用 Vs Code 进行 Angular 项目。昨天,当我输入“ng...”之类的内容时,它显示了 *ngFor、*ngIf、*ngModel ..... 今天它不再是这样了。有人能帮助我吗。抱歉给您带来不便,我现在无法发布图片。
x.name和imgname具有相同的类型(字符串)和相同的值“ comcardpro_capsule_model_2”。但是为什么findIndex()函数返回-1?请给我解释一下。
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
})
}
Run Code Online (Sandbox Code Playgroud)
预期结果将是数组中元素的索引,而不是-1。