How to check if array contains at least one object ?

前端 未结 5 1901
余生分开走
余生分开走 2021-02-08 13:04

I want to check if array contains object or not. I am not trying to compare values just want to check in my array if object is present or not?

Ex.

$arr =         


        
5条回答
  •  猫巷女王i
    2021-02-08 13:34

    I want to check if array contains object or not

    Use some to simply check if any item of the array has value of type "object"

    var hasObject = $arr.some( function(val){
       return typeof val == "object";
    });
    

提交回复
热议问题