jq杂项方法/工具方法----isArray()

$.isArray()函数用于判断指定参数是否是一个数组。返回布尔值。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
</head>
<body>
    <div class="box"></div>
    <div class="box"></div>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    <script>
    console.log($('.box'));
    var res = $.isArray($('.box'));
    console.log(res);
    
    </script>
</body>
</html>

 另一个例子~

arr = [1,2,3,4];
    res = $.isArray(arr);
    console.log(res);

返回: true

$.inArray()  在数组中查找指定值,并返回第一次出现的索引(没有找到,返回-1)源数组不会受到影响

接受三个参数,第一个是要查找的内容,第二个是查找的目标数组,第三个值规定检索开始的位置(包含当前值的位置)

举个栗子( ̄、 ̄)

    arr = ['hello',5,5,'hello',8];
    res1 = $.inArray('hello',arr);
    console.log(res1);
    res2 = $.inArray('hello',arr,2);
    console.log(res2);

res1:0

res2 : 3

猜你喜欢

转载自www.cnblogs.com/sandraryan/p/11528193.html