ES6擴充套件

2022-06-25 10:54:12 字數 1287 閱讀 5170

模板字串和標籤模板

const getcourselist = function

() , , ]}};

const =getcourselist();

function

foo(val)

if(status) ) ` }$`

);});

let ul = document.createelement('ul');

ul.innerhtml = arr.join('');

} else

padstart padend

repeat

console.log(repeat('s', 3));

}

startswith endswith

includes

if (str.includes('a promise'))

}

字串轉陣列+遍歷

let str = 'promise';

//四種方法:轉成陣列後遍歷

var ostr =array.prototype.slice.call(str);

var ostr = str.split('');

const ostr =[...str];

const [...ostr] =str;

console.log(ostr);

//單個字元輸出

ostr.foreach(function

(word) );

對全是英文的字串中的大寫字元加密 a -> 100  b -> 99

const map = ;

const words = 'abcdefghijklmnopqrstuvwxyz';

ostr.foreach(

function

(word, index) );

console.log(ostr.join(''));

使用for-of遍歷字串

let str = 'promise';

let newstr = '';

const map = ;

for(let word of str)

console.log(newstr);

unicode是一項標準,包括字符集、編碼方案等

解決傳統的字元編碼方案的侷限

es6擴充套件

擴充套件 1.字串擴充套件 var str hello world substring 1,4 從第1個到第 4 1 個 substr 1,4 從第乙個往後面數四個 重要事項 與 slice 和 substr 方法不同的是,substring 不接受負的引數。indexof searchvalue,...

ES6 函式擴充套件

函式在js裡是相當重要的一部分了,es6裡也新增了一些函式方法,來看一下 test hello hello world test hello kill hello kill es6增加了函式引數預設值,可以直接在宣告引數的同時賦預設值,但是也可以後面重新賦值 test2 kill 括號內有引數x時,...

ES6函式擴充套件

函式引數的預設值 在es5中,我們想給函式乙個預設值,需要這樣寫 function add x,y 在es6中 可以這樣寫 function add x,y ss add dd ddss add ss dd ssdd add dd dd我們只需要在引數上直接寫上我們想要的預設值就好了。當我們給函式乙...