I'm trying ti use match() in order to parse through some text and return the amount of times the text shows up. I'm doing this by using a global match and then calling length on the array that is created from the match. Instead, I'm just getting a array with a single element.
$('button').click(function () {
checkword = "/" + specialWord + "/g";
finalAnswer = userText.match(specialWord);
console.log(finalAnswer);
$('#answer').html(finalAnswer + '<br>' + finalAnswer.length);
return finalAnswer;
});
For example my search for 'is' in "this is" should return an array with a length of two, correct?
Fiddle: http://jsfiddle.net/