美文网首页
JavaScipt代码集

JavaScipt代码集

作者: AC编程 | 来源:发表于2024-01-21 14:59 被阅读0次

    一、对象展开运算,赋值给新对象,并添加新属性

    let passParams = {
      ...queryParams.value,
      column:'report_time',
      assayState: '2'
    }
    

    二、JS解构

    2.1 数组解构
    let [a, b, c] = [1, 2, 3];
    

    等同于:

    let a = 1;
    let b = 2;
    let c = 3;
    
    2.2 对象解构
    let { foo, bar } = { foo: 'aaa', bar: 'bbb' };
    foo // "aaa"
    bar // "bbb"
    
    2.3 对象解构改字段名
    let obj = { first: 'hello', last: 'world' };
    let { first: f, last: l } = obj;
    f // 'hello'
    l // 'world'
    
    2.4 对象解构获取函数
    // 例一
    let { log, sin, cos } = Math;
    
    // 例二
    const { log } = console;
    log('hello') // hello
    

    三、JS深拷贝

    let rowValue = JSON.parse(JSON.stringify(row))
    

    四、forEach方法

    var user = [
         {
             id: 1,
             name: "李四"
         },
         {
             id: 2,
             name: "张三"
         }
     ]
    
    var userName = [];
    user.forEach((item)=>{
        userName.push(item.name);
    })
    console.log(userName); // ["李四", "张三"]
    

    相关文章

      网友评论

          本文标题:JavaScipt代码集

          本文链接:https://www.haomeiwen.com/subject/hxyeodtx.html