Javascript – check an element in object

/**
  * Code in javascript to check if an element exist in an object
  * @param obj: object
  * @param element : String
  * @return bool : TRUE(if exit)/FALSE(if not)
  */
obj.hasOwnProperty(element)
Advertisements

Javascript – check item in array

/**
  * Code in javascript to check if an item exist in an array
  * @param arr  : array
  * @param item : String
  * @return bool : TRUE(if exit)/FALSE(if not)
  */
inArray = function(arr, item) {
           return (arr.indexOf(item) != -1);
 }