Posted By

vaibhav011286 on 10/04/11


Tagged

javascript inarray


Versions (?)

Minimized JS in_array() function


 / Published in: JavaScript
 

URL: http://phpjs.org/functions/in_array:432

  1. function in_array(d, b, a) {
  2. var c = "", a = !! a;
  3. for (c in b) if (a && b[c] === d) return !0;
  4. else if (!a && b[c] == d) return !0;
  5. return !1
  6. };
  7.  
  8. // * example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']); // * returns 1: true
  9. // * example 2: in_array('vlado', {0: 'Kevin', vlado: 'van', 1: 'Zonneveld'});
  10. // * returns 2: false
  11. // * example 3: in_array(1, ['1', '2', '3']);
  12. // * returns 3: true // * example 3: in_array(1, ['1', '2', '3'], false);
  13. // * returns 3: true
  14. // * example 4: in_array(1, ['1', '2', '3'], true);

Report this snippet  

You need to login to post a comment.