Posted By

uberdragon on 09/21/13


Tagged

array values


Versions (?)

Method to determine if all values in an array are the same.


 / Published in: JavaScript
 

Usage: var a = ['a','a','a']; var b = a.AllValuesSame(): //true

var a ['1','1','2']; var b = a.AllValuesSame(); //false

  1. Array.prototype.AllValuesSame = function(){
  2.  
  3. if(this.length > 0) {
  4. for(var i = 1; i < this.length; i++)
  5. {
  6. if(this[i] !== this[0])
  7. return false;
  8. }
  9. }
  10. return true;
  11. }

Report this snippet  

You need to login to post a comment.