js中Array.prototype.find() 方法在对象数组上无效果该怎么办

js中Array.prototype.find() 方法在对象数组上无效果该怎么办,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

我在使用Array.prototype.find() 方法时,发现在对象数组上没有正确返回,过程如下:

roleResourceList是个对象数组:

js中Array.prototype.find() 方法在对象数组上无效果该怎么办

里面的数据是这样的:

js中Array.prototype.find() 方法在对象数组上无效果该怎么办

调用find()方法:

js中Array.prototype.find() 方法在对象数组上无效果该怎么办

debugger下看到明明是true了,却最终返回undefined

js中Array.prototype.find() 方法在对象数组上无效果该怎么办

js中Array.prototype.find() 方法在对象数组上无效果该怎么办

好神奇有木有?

原来啊,不能直接这么比较,对象的话,要放在一个方法里比较:

js中Array.prototype.find() 方法在对象数组上无效果该怎么办

这样结果就对啦!

js中Array.prototype.find() 方法在对象数组上无效果该怎么办

看完上述内容,你们掌握js中Array.prototype.find() 方法在对象数组上无效果该怎么办的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注行业资讯频道,感谢各位的阅读!