你不知道的那些字符串方法~

  • anchor / small / big / fontsize / blink / bold / italics / strike
    都是用来创建标签

    // 添加锚点用的
    const txt="context";
    const htmla = txt.anchor("maodian");
    console.log(htmla); // context
    
    const worldString = 'Hello, world';
    console.log(worldString.small());     // Hello, world
    console.log(worldString.big());       // Hello, world
    console.log(worldString.fontsize(7)); // Hello, world
    // 用来修饰字符串
    const worldString = 'Hello, world';
    console.log(worldString.blink());   // Hello, world
    console.log(worldString.bold());    // Hello, world
    console.log(worldString.italics()); // Hello, world
    console.log(worldString.strike());  // Hello, world
    
  • at / charAt / charCodeAt

    // 传入角标,返回一个新的字符串
    const txt="text";
    const txt1= txt.at(2);
    console.log(txt,txt1); // text x
    
    const txt="text";
    const txt1= txt.charAt(2);
    console.log(txt,txt1); // text x
    
    // charCodeAt() 方法返回 0 到 65535 之间的整数,表示给定索引处的 UTF-16 代码单元
    const txt="text";
    const txt1= txt.charCodeAt(2);
    console.log(txt,txt1); // text 120
  • codePointAt

    // codePointAt() 方法返回 一个 Unicode 编码点值的非负整数。
    const txt="text";
    const txt1= txt.codePointAt();
    console.log(txt1); // 116
  • concat

    // concat 字符串链接。
    const txt="text";
    const txt1= "text2";
    console.log(txt.concat(txt1)); // texttext2

    吃饭回来继续~

你可能感兴趣的:(javascript)