我有一个字符串数组,并且想在某些操作后过滤掉一个特定的字符串。但是,似乎我在那里做错了什么。
this.displayUser.followers.filter(userId=>userId !== this.loggedUser.userid);
在这里,followers 是一个字符串数组 ->string[]
并且在某些操作时(例如,取消关注);我想从显示的用户的关注者列表中删除登录用户的 ID。但是,此过滤器操作似乎不起作用。
另一方面,我尝试使用 splice,它工作得非常好。
this.displayUser.followers.splice(
this.displayUser.followers.findIndex(userId=>userId === this.loggedUser.userid)
,1);
我无法理解我在第一种方法中做错了什么?