ES6入门教程——8、ES6字符串

一、一般用法

let string = "apple,banana,orange";

string.includes("banana"); // true

string.startsWith("apple"); // true

string.endsWith("apple"); // false

string.startsWith("banana",6) // true

二、字符串重复

console.log("Hello,".repeat(3));  // "Hello,Hello,Hello,"
console.log("Hello,".repeat(-0.5));  // "" 

三、字符串补全

console.log("h".padStart(5,"o"));  // "ooooh"
console.log("h".padEnd(5,"o"));    // "hoooo"
console.log("h".padStart(5));      // "    h"

四、模板字符串

多行的写法:

let string1 = `Hey,

can you stop angry now?`;

console.log(string1); // Hey, // can you stop angry now?

五、标签模板

alert`Hello world!`;

// 等价于

alert('Hello world!');

 

你可能感兴趣的:(ES6入门教程,es6/es7,vue)