• good


    1,将NodeList 转化成 Array
    var divs = Array.from(document.querySelectorAll('div'));
    2,将 arguments 转化成 Array
    function something() {
    var args = Array.from(arguments);

    // Array['yes', 1, {}]
    }
    something('yes', 1, {});
    3,将 String 转化成 Array
    Array.from('JavaScript'); // 很像'JavaScript'.split('')

    4,+ string to number
    console.log(+new Date())

    conected && login();
    this.name = name || "Oliver Queen";

    var length = array.length;
    for(var i = 0; i < length; i++) {
    console.log(array[i]);
    }

    var array = [1,2,3,4,5,6];
    console.log(array.slice(-1)); // [6]
    console.log(array.slice(-2)); // [5,6]
    console.log(array.slice(-3)); // [4,5,6]

    数组截断
    var array = [1,2,3,4,5,6];
    console.log(array.length); // 6
    array.length = 3;
    console.log(array.length); // 3
    console.log(array); // [1,2,3]

    替换所有
    var string = "john john";
    console.log(string.replace(/hn/, "ana")); // "joana john"
    console.log(string.replace(/hn/g, "ana")); // "joana joana"
    合并数组
    var array1 = [1,2,3];
    var array2 = [4,5,6];
    console.log(array1.concat(array2)); // [1,2,3,4,5,6];

    var elements = document.querySelectorAll("p"); // NodeList
    var arrayElements = [].slice.call(elements); // Now the NodeList is an array
    var arrayElements = Array.from(elements); // This is another way of converting

    var list = [1,2,3];
    console.log(list.sort(function() { Math.random() - 0.5 })); // [2,1,3]

  • 相关阅读:
    android studio Cannot resolve symbol '@drawable/XXX'等问题解决办法
    android面试
    Android动态增量
    客户端传递Cookie到WebView中
    Android事件传递机制
    Activity状态保存的两种方式
    Activity Window View之间的关系
    Git学习笔记
    Android Log命令常用方法
    ListView 中点击Item中的Button删除当前行
  • 原文地址:https://www.cnblogs.com/jayruan/p/5923110.html
Copyright © 2020-2023  润新知