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

PHOTO EMBED

Wed Oct 21 2020 17:08:49 GMT+0000 (Coordinated Universal Time)

Saved 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_copyCOPY