Arrays FindIndex值连续返回为-1?

Arrays FindIndex值连续返回为-1?,arrays,angular,typescript,local-storage,Arrays,Angular,Typescript,Local Storage,我有以下的表达: 这将获取通过URL传递的ID参数: editUserId = this.route.snapshot.paramMap.get('id'); 然后,我在一个对象数组上使用FindIndex来查找数组中元素的索引,该索引等于从URL获取的上述ID值: this.userToUpdate = this.allUsers.findIndex((x: any) => x.UserId === this.editUserId); (这个。诱惑者)是我的对象数组 尽管findIn

我有以下的表达:

这将获取通过URL传递的ID参数:

editUserId = this.route.snapshot.paramMap.get('id');
然后,我在一个对象数组上使用FindIndex来查找数组中元素的索引,该索引等于从URL获取的上述ID值:

this.userToUpdate = this.allUsers.findIndex((x: any) => x.UserId === this.editUserId);
(这个。诱惑者)是我的对象数组

尽管findIndex连续返回值-1。。 我尝试了以下两种方法,它们都返回相同的错误:“此条件将始终返回'false',因为'number'和'string | null'类型没有重叠”:


有什么原因可以解释为什么会发生这种情况吗?

第七,我想editUserId可能是数字,您可以试试:


this.userToUpdate=this.allUsers.findIndex((x:any)=>Number(x.UserId)==Number(this.editUserId))从参数中获取ID时,它是一个字符串UserId属性的类型是什么?
this.userToUpdate = this.allUsers.findIndex((x: any) => parseInt(x.UserId) === this.editUserId);

this.userToUpdate = this.allUsers.findIndex((x: any) => Number(x.UserId) === this.editUserId);