0

I would like to check multiple conditions based on an extensible array of variables. What's the method to check them ?

For example:

a = 0;
b = 1;
c = 0;

if (a == 0 && b == 0 && c == 0) {
    console.log("all a,b,c variables == 0")
}

Good. Now for an array ?

arr = ["a", "b", "c", "d", ...];

if (for i = 0; i < arr.length; i ++ { arr[i] == 0 && }) {
    console.log("all arr variables == 0")
}

I think I'm going the wrong way here... Is there a solution check a lot of statements based on an array ?

Thank you for your help.

2
  • 2
    "I think I'm going the wrong way here..." Since your code has syntax errors, definitely yes. What exactly are you trying to achieve? "Is there a solution check a lot of statements based on an array ?" What exactly does that mean? Commented Apr 25, 2016 at 16:44
  • what means ["a", "b", "c", "d" ...]? Commented Apr 25, 2016 at 16:44

1 Answer 1

4

How about Array.prototype.every?

const array = [0, 0, 0];
array.every(x => x === 0); // true
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.