How to check if all array items are equal in JavaScript

1 Answer

0 votes
var arr = [1, 1, 1, 1, 1];

var tf = arr.every(function(item, i, list) { return item === list[0]; });  
if (tf)
    document.write("true");
else    
    document.write("false");
    
    

/*
run:

true
  
*/

 



answered Jul 25, 2017 by avibootz
...