📅  最后修改于: 2022-03-11 15:02:23.903000             🧑  作者: Mango
function checkArrayEqualElements(_array)
{
if(typeof _array !== 'undefined')
{
return !!_array.reduce(function(a, b){ return (a === b) ? a : NaN; });
}
return "Array is Undefined";
}
//usage
let myArray1 = ["Javascript", "Javascript", "Javascript", "Javascript"];
let myArray2 = ["Javascript",1,"Javascript"];
let myArray3 ;
console.log(checkArrayEqualElements(myArray1));
console.log(checkArrayEqualElements(myArray2));
console.log(checkArrayEqualElements(myArray3));