Passing an Object to Switch Case Javascript
<p>I wanted to have a switch/case statement that accepts an object in Javascript. </p>

<p>The function looks like this. </p>

<pre><code>const validate = (values) =&gt; { values is an object, can be accessed like so (values.bar, values.foo)
  const errors = {}

  switch(values) {
    case !values.bar || values.bar === '':
       errors.bar = 'Enter bar'
    case values.bar.length &lt; 10: 
       errors.bar = 'Bar is too short'
    case !values.foo || values.foo === '':
       errors.foo = 'Enter foo'
    ...

    default: 
      return errors
  } 
}
</code></pre>

<p>This doesn't work and I have used an if/else statement instead, but I feel like a switch/case would be perfect for this kind of example. Thoughts?</p>