【发布时间】:2011-11-13 16:09:02
【问题描述】:
您好,我真的很难为“从包含字符串的已填充数组返回索引数组”的函数编写代码,当它与搜索词匹配时。 因此,如果搜索词匹配数组元素中的一个或多个单词,无论其顺序如何,它都应该返回这些单词在数组中明显存在的索引。不使用 jquery grep 功能。 这是一些代码来说明我的意思。
array_test = ["Today was hot","Tomorrow will be hot aswell", "Yesterday the weather was not so good","o1234 t12345"]
function locateSearch(array_test,searchTerm){
var myArray = [];
for(i=0;i<array_test.length;i++){
if(...) // what should i be testing here, this is where i have been going wrong...
myArray[myArray.length] = i;
}
return myArray;
}
document.write(locateSearch,'ot') //this should return indexes [0,1,2,3]
对不起,如果我没有很好地解释这一点,感谢您的帮助。谢谢。
【问题讨论】:
标签: arrays function pattern-matching javascript