輸入:爲什麼我在下面的ES6 for循環中得到「undefined不是函數」?
first line
second line third line
fourth line
的代碼:
let res = str.split('\n\n')
for (let result of res) {
res = `<p class="blockquote">${res.replace(/^> /gm, '')}</p>`
}
console.log(`text: ${res}`)
str.split('\n\n')
輸出first line,second line third line,fourth line
。我的預期。
現在我想使用for
循環來取每個項目並用p
標記包圍它。然而,我得到以下錯誤:
TypeError: undefined is not a function
我對ES6不是很有經驗。循環有問題嗎?
什麼是你想到底要得到什麼?四個字符串包裝在blockquote標籤中的數組?你能顯示所需的輸出嗎? – Touffy