Minimized JS in_array() function


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  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);

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.