Posted By


iTony on 03/22/10

Tagged


Statistics


Viewed 124 times
Favorited by 0 user(s)

Array.prototype.indexOf()


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



Copy this code and paste it in your HTML
  1. //This prototype is provided by the Mozilla foundation and
  2. //is distributed under the MIT license.
  3. //http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
  4.  
  5. if (!Array.prototype.indexOf)
  6. {
  7. Array.prototype.indexOf = function(elt /*, from*/)
  8. {
  9. var len = this.length;
  10.  
  11. var from = Number(arguments[1]) || 0;
  12. from = (from < 0)
  13. ? Math.ceil(from)
  14. : Math.floor(from);
  15. if (from < 0)
  16. from += len;
  17.  
  18. for (; from < len; from++)
  19. {
  20. if (from in this &&
  21. this[from] === elt)
  22. return from;
  23. }
  24. return -1;
  25. };
  26. }

URL: http://www.electrictoolbox.com/javascript-indexof/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.