我試圖計算某些單詞出現在字符串中的次數。每次我運行它,我得到一個使用字符串中的搜索方法
未捕獲TypeErro:undefined是不是一個函數
我只是實際需要計算的時代「主要」每次出現的數量。
下面是我的代碼:
for(var i = 0; i < sortedarray.length; i++)
{
if(sortedarray.search("Multimedia") === true)
{
multimedia += 1;
}
}
console.log(multimedia);
這裏是存儲在一維數組我的csv文件。
"NAME","MAJOR","CLASS STANDING","ENROLLMENT STATUS"
"Smith, John A","Computer Science","Senior","E"
"Johnson, Brenda B","Computer Science","Senior","E"
"Green, Daisy L","Information Technology","Senior","E"
"Wilson, Don A","Information Technology","Junior","W"
"Brown, Jack J","Multimedia","Senior","E"
"Schultz, Doug A","Network Administration","Junior","E"
"Webber, Justin","Business Administration","Senior","E"
"Alexander, Debbie B","Multimedia","Senior","E"
"St. John, Susan G","Information Technology","Junior","D"
"Finklestein, Harold W","Multimedia","Freshman","E"
如果有人需要更多的代碼,我可以編輯並放了更多。我只是想保持簡單。 – user4073939 2014-09-24 09:14:40
沒有'Array.search'這樣的東西。 – Cerbrus 2014-09-24 09:15:19
你有效的錯誤說'Array.prototype.search是未定義的'。你必須找到另一種方式來做你的搜索。 – phuzi 2014-09-24 09:15:46