1、首先替換 String.prototype.replace
效果
const str = 'I like frontend. I like JavaScript.';
const newStr = str.replace('like', 'love');
newStr="I love frontend. I like JavaScript."
單一替換第一個匹配項 然后全部替換怎么破?
const newStr = str.replaceAll('like', 'love');
newStr="I love frontend. I love JavaScript."
2、Promise.any(promises).then(
(first) => {
// 任何一個 Promise 完成了
},
(error) => {
// 所有的 Promise 都拒絕了
}
);
3、?? 雙問號神器
假設 lrealCount=null 或者undefined 的時候就給一個默認值
如果 lrealCount =0時 let count = realCount || '無法獲取' 那么此時content就等於“無法獲取”了
此時無法忍受了 那么怎么讓其等於0呢
let count = realCount ?? '無法獲取' 去試試唄 哈哈
4、數字分隔符 _
let x = 2_3333_3333 x=233333333
5、Intl.ListFormat
const list = ['Apple', 'Orange', 'Banana']
new Intl.ListFormat('en-GB', { style: 'long', type: 'conjunction' }).format(list);
// "Apple, Orange and Banana"
new Intl.ListFormat('zh-cn', { style: 'short', type: 'conjunction' }).format(list);
// 會根據語言來返回相應的格式化操作
// "Apple、Orange和Banana"