1

When I console.log(req.body.sectionAData), I got this result:

{
  sectionAData: { AQ1: '5', AQ2: '4', AQ3: '5' }
}

So I continue with this:

const { AQ1, AQ2, AQ3} = req.body.sectionAData   
console.log( AQ1, AQ2, AQ3)

and the result is:

5 4 5

What I'm trying to achieve is to validate all the AQ1, AQ2 and AQ3 are within the range of 1 to 5

If either one is not in range, then json.send a message.

How should I go about it? Thanks

lll
  • 65
  • 1
  • 9
  • Does this answer your question? [How to iterate over a JavaScript object?](https://stackoverflow.com/questions/14379274/how-to-iterate-over-a-javascript-object) – derpirscher Feb 28 '22 at 11:24

1 Answers1

1

You can do like this:

const check = [AQ1, AQ2, AQ3].every(e => e >= 1 && e <= 5)
if (!check) { 
  // do stuff 
}