javascript - Search certain words in a string from a big list of array Jquery -


how search through each word in string of

matches array?

here prototype:

        $("#latte").on("click", function() {              $('#lattepool').load('dictionary.txt');               var text = $("#lattepool").text().touppercase();             var words = text.split("\n");             var dictionary = new array();             for(var i=0; < words.length; i++) {                 dictionary[i] = words[i];             };              $("#notes p").each(function(){                 var namefound = $.inarray($(this).text().trim().touppercase(), dictionary);                 if (namefound === -1){                 } else {                     alert($(this).text() + " found in array");                }             });          }); 

when user click on #latte button, loads dictionary.txt text temporary pool call #lattepool, breaks down individual words , long array.

then, wehn user paste in contenteditable div #notes, needs find each words in

tag words in dictionary array.

currently works single word in

, not long string.

any ideas make check through each word of

array?

many thanks~!!!

instead of $("#notes p").each need p tag text , split space , loop through find out words.

try this:

$("#latte").on("click", function() {         $('#lattepool').load('dictionary.txt', function(){             var text = $("#lattepool").text().touppercase();             var words = text.split("\n");             var dictionary = new array();             for(var i=0; < words.length; i++) {                 dictionary[i] = words[i];             };             var contenteditabletxt = $("#notes p").text();             var splitcnteditabletxt = contenteditabletxt.split(" ");             $.each(splitcnteditabletxt,function(key,val){                    var namefound = $.inarray(val.trim().touppercase(), dictionary);                 if (namefound === -1){                 } else {                     alert(val + " found in array");                }             });         });      }); 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -