• jQuery的方法


    要操作的数组 let arr = [1, 2, 3, 4];

    each

    类似数组的forEach

        $.each(arr, function (index, value) {
                console.log(index, value);
            })
    
    • 1
    • 2
    • 3

    extend

    对象扩展(对象的浅拷贝,类似object.extend)
    返回的是两个对象的引用

    let res1 = $.extend({ name: "zhangsan" }, { age: 23, height: 180 });
    console.log(res1);
    
    • 1
    • 2

    grep

    数组过滤:类似于数组的filter方法

    let res2 = $.grep(arr, function (value, index) {
                console.log(value, index);
                return index % 2;
            })
            console.log(res2);//返回下标为偶数
    
    • 1
    • 2
    • 3
    • 4
    • 5

    makeArray

    将类数组对象转化为数组对象,类似array.from

        let res3=$.makeArray($("*"));
            console.log($("*"));
            console.log(res3);
    
    • 1
    • 2
    • 3

    toArray

    将jQuery对象转化为数组对象

     let res4=$("*").toArray();
            console.log(res4);
    
    • 1
    • 2

    map

    数组映射;类似数组的map方法

     let res5=$.map(arr,function(element,index){
                console.log(element,index);
                return element*100;
            })
            console.log(res5);
    
    • 1
    • 2
    • 3
    • 4
    • 5

    inArray

    类似于数组的indexof
    返回第一个元素的下标,没找到返回-1
    参数一:指定查找的元素
    参数二:查找的目标数组

    let res6=$.inArray(3,arr);
            console.log(res6);
    
    • 1
    • 2

    merge

    数组合并,类似数组的concat
    多个数组继续在后面拼

    let res7=$.merge(arr,[100,200,300])
           console.log(res7);
    
    • 1
    • 2

    unique

    去除数组中连续重复的元素

     let res8=$.unique([1,1,1,2,2,55,55,8,3,2,1])
           console.log(res8);
    
    • 1
    • 2

    trim

    去除字符转开头和结尾的空白符

     let res9=$.trim("   hello     ")
           console.log(res9);
    
    • 1
    • 2

    param

    将对象转换成key=value&key=value形式

    let obj={
            name:"张三",
            age:20
           }
           let res10=$.param(obj);
           console.log(res10);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
  • 相关阅读:
    基础篇——REST风格开发
    TrOCR – 基于 Transformer 的 OCR 入门
    免杀对抗-宏免杀
    深度学习计算 - 参数管理
    代码签名证书续费
    AI智能分析视频监控系统如何助力智慧民宿规范化、安全最大化?
    java基于微信小程序的在线外卖订餐系统 uniapp
    嵌入式软件架构设计-消息交互
    React的diff算法原理
    IDEA配置Maven
  • 原文地址:https://blog.csdn.net/weixin_68658847/article/details/127994223