Posts with tag: web

This is a function I find myself writing quite often, so I thought I would just post it here for future reference. It's purpose is simple, check if an array contains an element with a given key and value, if it does, return it other wise return a null value.

function FindObjectByKeyInArray(array, key, value){
   for(var i = 0; i < array.length; i++) {
      if (array[i][key] == value) {
         return array[i];
      }
   }
   return null;
}