jquery - How do I create an array from a looping val? -


i have partial piece of code compares text in contenteditable div called #notes array created text document called dictionary.txt.

it loops through split text #notes called splitcnteditabletxt , checks whether matches. if matched, creates new span matched value in it.

now, want create new array using matched val loop. ideas of creating array loop? here's partial code. thank again~!!!

$('#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").text();     var splitcnteditabletxt = contenteditabletxt.replace(/([.,-=/])/g," ").split(" ");      //alert(splitcnteditabletxt); //debug      $.each(splitcnteditabletxt,function(key,val){         var namefound = $.inarray(val.trim().touppercase(), dictionary);         if (namefound === -1){         } else {             $("#notes").append('<span class="matchedword">'+val+'</span>');         }     }); }); 

  1. declare blank array before above code
    var vals_array = [];
  2. push 'val' every time found array. change else statement this:

    else {      $("#notes").append('<span class="matchedword">'+val+'</span>');      vals_array.push(val);  }

  3. p.s.: save space , change if-else statement this:

    if (namefound !== -1){      $("#notes").append('<span class="matchedword">'+val+'</span>');      vals_array.push(val);  }


Comments

Popular posts from this blog

Add new key value to json node in java -

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

javascript - Highcharts Synchronized charts with missing data points -