• 打印字符串,数组,对象,函数的原型方法


    字符串

    Reflect.ownKeys(String.prototype)
    
    • 1
    // 部分不重要的做了删减
    [
       
        "anchor",
        "at",
        "big",
        "blink",
        "bold",
        "charAt",
        "charCodeAt",
        "codePointAt",
        "concat",
        "endsWith",
        "fontcolor",
        "fontsize",
        "fixed",
        "includes",
        "indexOf",
        "italics",
        "lastIndexOf",
        "link",
        "localeCompare",
        "match",
        "matchAll",
        "normalize",
        "padEnd",
        "padStart",
        "repeat",
        "replace",
        "replaceAll",
        "search",
        "slice",
        "small",
        "split",
        "strike",
        "sub",
        "substr",
        "substring",
        "sup",
        "startsWith",
        "toString",
        "trim",
        "trimStart",
        "trimLeft",
        "trimEnd",
        "trimRight",
        "toLocaleLowerCase",
        "toLocaleUpperCase",
        "toLowerCase",
        "toUpperCase",
        "valueOf"
    ]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    var str = 'helloworld45zanlan'
    console.log(str.endsWith('zanlan'));// true
    console.log(str.startsWith('helloworld')); // true
    console.log(str.includes('45')); // true
    console.log('zanlan-'.repeat(3));// 'zanlan-zanlan-zanlan-'
    console.log(/hell/.test(str)) // true
    console.log(str.length)//18
    
    'aAcd'.charCode.At(1) // 65
    'aAcd'.charCode.At(0) // 97
    String.fromCharCode(65)// "A"
    String.fromCharCode(97)// "a"
    'aAcd'.toLowerCase() // 'aacd'
    'aAcd'.toUpperCase() // 'AACD'
    '123456789'.substr(1,3) // "234"  截取长度为3
    '123456789'.substring(1,3) // "23"
    '123456789'.slice(1,3) // '23'
    '123456789'.slice(-3,-1) // '78'
    '123456789'.slice(-3) // '789'
    '123456789'.substr(-3) // '789'
    '123456789'.slice(30) // ''
    '123456789'.substr(30) // ''
    
    var str = "The full name of China is the People's Republic of China.";
    console.log(str.indexOf("China")) // 17
    console.log(str.indexOf("China",18)) // 51    18 ~ 终止位置56, 范围内找
    console.log(str.lastIndexOf("China")) // 51
    console.log(str.lastIndexOf("China"),50) // 17     50 ~ 起始位置0 范围内找
    console.log(str.indexOf("America")) // -1
    console.log(str.lastIndexOf("America")) // -1
    console.log(str.search("China")) // 17  和indexOf功能一样,但是不能设置第二个参数
    console.log(str.replace('is','yes')) // "The full name of China yes the People's Republic of China.";
    console.log(str.replace(/china/gi,'China-China')) // The full name of China-China is the People's Republic of China-China.;
    " Hello World!   ";
    console.log(" Hello World!   ".trim())
    
    var str = "HELLO WORLD";
    str[0] = "A"; // 只读的,不产生错误,但不会工作
    console.log(str[0])// 返回 H
    console.log(str[30]) // undefined
    console.log(str.charAt(30)) // ""
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41

    数组

    Reflect.ownKeys(Array.prototype)
    
    • 1
    [
        "length",
        "constructor",
        "at",
        "concat",
        "copyWithin",
        "fill",
        "find",
        "findIndex",
        "lastIndexOf",
        "pop",
        "push",
        "reverse",
        "shift",
        "unshift",
        "slice",
        "sort",
        "splice",
        "includes",
        "indexOf",
        "join",
        "keys",
        "entries",
        "values",
        "forEach",
        "filter",
        "flat",
        "flatMap",
        "map",
        "every",
        "some",
        "reduce",
        "reduceRight",
        "toLocaleString",
        "toString",
        "findLast",
        "findLastIndex",
        null,
        null
    ]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40

    对象

    Reflect.ownKeys(Object.prototype)
    
    • 1
    [
        "constructor",
        "__defineGetter__",
        "__defineSetter__",
        "hasOwnProperty",
        "__lookupGetter__",
        "__lookupSetter__",
        "isPrototypeOf",
        "propertyIsEnumerable",
        "toString",
        "valueOf",
        "__proto__",
        "toLocaleString"
    ]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    函数

    Reflect.ownKeys(Function.prototype)
    
    • 1
    [
        "length",
        "name",
        "arguments",
        "caller",
        "constructor",
        "apply",
        "bind",
        "call",
        "toString",
        null
    ]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    统计字符串出现的次数,按权重排序
    字符统计

    var brr = "aaddccdc".split("");
    var map = new Map();
    brr.forEach((item) => {
        map.set(item, (map.get(item) || 0) + 1);
    });
    var arr = Array.from(map)
    arr.sort(function (a, b) {
        if (a[1] - b[1] == 0) {
            return a[0].charCodeAt(0) - b[0].charCodeAt(0)
        }
        return b[1] - a[1]
    })
    var result = arr.reduce(function (res, item) {
        return res += item[0]
    }, '')
    console.log(result) // "cda"
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
  • 相关阅读:
    基于SSM的高校餐厅防疫管理系统
    API设计中性能提升的10个建议
    如何修改别人的神经网络,人工神经网络通过调整
    type_traits元编程库学习
    【毕业设计源码】基于Python的校园生活助手(二手+活动+论坛+新闻)信息系统
    Llama2 论文中译版——开放式基础和微调聊天模型
    Vue2.0 —— Vue.set(vm.$set) 源码探秘
    【黄色手套22】12番外:图形库
    Springboot乐动健身房管理系统6xl64计算机毕业设计-课程设计-期末作业-毕设程序代做
    什么是SRRC认证?SRRC认证是什么?
  • 原文地址:https://blog.csdn.net/formylovetm/article/details/126306118