我正在尝试将数组中的字符串作为句子输出,并且在单词之间输出用于分隔字符串的逗号,这很烦人。
let words = document.getElementById("Words");
let wordAr = ["This" , "is" , "a" , "test"];
let textIn = document.getElementById("Input");
let timer = 0;
let WPM = 0;
let text = document.getElementById("text");
words.innerHTML = wordAr.slice(0,4);
window.addEventListener("keydown", function(key){
if(key.keyCode == 32){
for (let i=0; i < wordAr.length; i++){
WPM++;
};
console.log("test");
};
});
答案 0 :(得分:2)
您可以join()
使用空格。
let wordAr = ["This" , "is" , "a" , "test"];
console.log(wordAr.join(' '))