1. 並行請求,等待多個異步請求結束後處理結果
const detail = 一個異步請求
const comments = 另一個異步請求
Promise.all([detail,comments]).then(res=>{
//這裏就是等待兩個異步請求都結束的結果處理
//並且res[0]是detail的結果,res[1]代表comments的結果
})
另一個相關標籤,Promise.race(競爭),則表示任何一個先完成了就處理。
2. 數組中包含某一個元素 ES6
let words = 一個數組
const has =words.includes(keyWord)
// 數組words中有keyWord則has返回true
3. 在</script>
後面添加一個<script></script>
let scriptString = `<script type="test"><\/script><sctipt><\/script>`
let patter1 = `<\/script>`
let replacetest = `<\/script><script>let all = 1;console.log("name")<\/script>`
let stringTest = scriptString.replace(patter1,replacetest)
console.log(stringTest)
//<script type="test"></script><script>let all = 1;console.log("name")</script><sctipt></script>