I have an array if all array items are 0 then I need to generate a warning. For example,
if myArray = [0,0,0,0] ;; Then the warning ('all zero'); Other alerts ('all are not zero');
Thanks.
You are looking for something like this:
var flag = 0 ; For (i = 0; i & lt; myArray.length; ++ i) {if (myArray [i]! == 0) {flag = 1; break; }} If (flag) {warnings ('all are not zero'); } And {warnings ('all zero'); }
If you do not do any of the following, you want a non-loop solution:
var arr = [0 , 0, 0, "", 0], arrj = arr.join (''); If ((/ [^ 0] /) Exec (arrj) || arr.length! = Arrj.length) {Warning ('all are not zero'); } And {warnings ('all zero'); }
If there are only 0
in the array, the "All Zero" will return:
< Pre> var arr = [0,0,0,0]; Const isAllZero =! Arr.some (el = & gt; L! == 0);
Comments
Post a Comment