title: Yup remove invalid fields from object?
body: <p>I have an array of objects I want to validate using <code>Yup</code>, and get rid of any fields in the object which do not pass the validation. Here is the <code>Yup</code> schema I built:</p>
  <pre><code>const schema = Yup.object().shape({
    id: Yup.string().nullable(false),
    country: Yup.string().trim().nullable(false),
    firstname: Yup.string().trim().nullable(false),
    lastname: Yup.string().trim().nullable(false),
    email: Yup.string().trim().nullable(false).email(),
    phoneNum: Yup.string()
      .trim()
      .test(&quot;phone&quot;, &quot;&quot;, (value) =&gt; isPossiblePhoneNumber(`+1${value}`))
  });
  
  const schemaArr = Yup.array().of(schema);
  </code></pre>
  <p>I'm then calling this on my array of objects like this:</p>
  <pre><code>const sanitization = await schemaArr.cast(input, {
    abortEarly: false,
    stripUnknown: true
  });
  </code></pre>
  <p>However, this doesn't remove the invalid fields. Does anyone know how I can accomplish such a thing?</p>
  <p><strong>Here is my code:
  <a href="https://codesandbox.io/s/wizardly-pascal-8865e" rel="nofollow noreferrer">https://codesandbox.io/s/wizardly-pascal-8865e</a></strong></p>