title: How do I sanitize/clean up string values within Javascript objects?
body: <p>I'm trying to find the best way to take data from a form input and remove extraneous white space from strings before they are submitted to our database via an API call. I'm working with React in next.js</p>
  <p>The data takes this form:</p>
  <pre><code>const data = { 
    email: 'test@testemail.com',
    website: 'http://www.fake.com'
    name: 'Fake Name  '
  }
  </code></pre>
  <p>And I want to avoid having users submit strings with empty spaces at the end to avoid database issues. Currently, I have a <code>.trim()</code> on event handlers called on the actual form inputs themselves but want an API call failsafe to dry up the code a little bit. Just can't figure out the best way to do this.</p>