这段代码:
var text = "filler text filler text Michael filler text Michael";
var myName = 'Michael';
var hits = [];
for (var i = 0; i < text.length; i++){
if (text[i] === "M"){
for (var j = i; j < (i + myName.length); j++){
hits.push(text[j]);
myName.toString();
}
}
}
if (hits === 0){
console.log("Your name wasn't found!");
}
else {
console.log(hits);
}
打印出 ["M" "i" "c" "h" "a" "e" "l"] 我如何让它打印出 "Michael"?谢谢