Both Array.prototype.indexOf and String.prototype.indexOf (as well as all their counterparts in other languages) return -1 when a match is not found. This can seem less-than-obvious to new learners. I often use this example to illustrate why:

var getIndex = function(array, element){
  var i = array.length;
  while(--i >= 0){  // this could be "i in array" as well
    if(array[i] == element){
  return i;