gpt4 book ai didi

javascript - 语法错误: Unexpected Identifier for loop through an array

转载 作者:行者123 更新时间:2023-12-03 06:17:25 27 4
gpt4 key购买 nike

编写一个循环和数组来搜索文本中的单词,并出现此语法错误,我一直在查看代码,但似乎没有注意到任何错误。

jshint multistr:true 

var text = "Usually, solar companies install\
solar panels on roofs but Elon Musk offers an\
entirely different and ingenious approach";

var myName = "Elon";

var hits = [];

for(var i=0; i <= text.length; i++) {
if(text[i] === 'E') {
for(var j = i; j < (myName.length + i); j++) {
hits.push(text[j]);
}
}
}

if (hits.length === [0]) {
console.log("Your name wasn't found!");
} else {
console.log(hits);
}

最佳答案

试试这个

var jshint_multistr = true;

而不是

jshint multistr:true 

关于javascript - 语法错误: Unexpected Identifier for loop through an array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39031605/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com