Word to Number

Convert word (ex: "two") to number (ex: "2") using jQuery.

by Preston Badeer

JavaScript

// Convert word to number (compatible with 0-10)
function wordNum(word)
{
  var words = new Array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten');

  for (w in word)
  {
    if($.inArray(word[w], words) == -1)
      continue;
    else
      return $.inArray(word[w], words) * 1;
  }
}