title: Best way to replace an array with its contents from inside an object
body: <p>I'm given the following JavaScript object:</p>
  <pre><code>{
      name: [
          {
              &quot;firstName&quot;:&quot;First &quot;,
              &quot;lastName&quot;:&quot;Last&quot;
          }
      ],
      age: 21
  }
  </code></pre>
  <p>The <code>name</code> property (or other similar complex props) are always provided as an object within an array, even though there can only ever be a single value.</p>
  <p>I need to save the information as an object that looks like this (without the array around the value of the <code>name</code> property):</p>
  <pre><code>{ 
      name: { 
          firstName: 'First ',
          lastName: 'Last' 
      }, 
      age: 21
  }
  </code></pre>
  <p>I need a generic function that doesn't reference a particular property name because that changes depending on the query. Here's my solution:</p>
  <pre><code>const object = {
      name: [{&quot;firstName&quot;:&quot;First &quot;,&quot;lastName&quot;:&quot;Last&quot;}],
      age: 21
  }
  const data = {}
  
  for (const property in object) {
      const value = object[property]
      if (Array.isArray(value)) {
          data[property] = value[0]
      } else {
          data[property] = value
      }
  }
  </code></pre>
  <p>Which returns the properly formatted object.</p>
  <p>My question is whether this is the most performant and/or most obvious way to get the result I'm looking for?</p>