0 points

Validates an object passed as a prop compared to "required" array


dashboard

Wed Oct 21 2020 17:08:49 GMT+0000 (UTC)

Posted by @nickarocho #vue.js

const requiredProps = ['title', 'name', 'etc'];

validator: function (heroObj) {
  // check to see if all the required props are passed in the object
  return requiredProps.every(requiredValue => (
    Object.entries(heroObj).some(([key, val]) => {
      // double check to make sure the value isn't 'undefined'
      return (requiredValue === key) && val;
    })
  ));
},
content_copy Copy