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() 方法在对象数组上无效果,捉急。。。

 

 

欢迎关注我的公众号:编程我也会