拿這個數組:楠JavaScript字符串拼接
errors [
"Your name is required.",
"An email address is required."
]
我想重複它,並創建這樣一個字符串:
"Your name is required.\nAn email address is required.\n"
使用此代碼:
var errors = ["Your name is required.","An email address is required."];
if (errors) {
var str = '';
$(errors).each(function(index, error) {
str =+ error + "\n";
});
console.log(str); // NaN
}
我在控制檯中獲得NaN
。爲什麼是這個,我該如何解決它?
在此先感謝。
另一件不錯的事情是在行尾和下一行的開頭。很難找到並且拿到你的字符串。 – pkopac