title: How to solve a problem with Array.sort Cannot assign to read only property '0' of object
body: <p>In my React App I'm getting an error in the sort functionality</p>
  <p><code>Uncaught TypeError: Cannot assign to read only property '0' of object '[object Array]'</code></p>
  <p>I have no idea what the problem is and the functionality is this:</p>
  <pre><code>const preparedSites = useMemo(
        () =&gt;
          sites
            .sort(sortSiteSelection(site))
            .map(elm =&gt; {
              const arr = [
                elm.siteId,
                elm.city,
                elm.state,
                elm.country,
                elm.address,
                elm.status,
              ];
              if (nearestSites.length)
                arr.push(
                  nearestSites.find(s =&gt; s.closestSiteId === elm.siteId).distance,
                );
              return arr;
            })
            .sort((a, b) =&gt; a[6] - b[6]),
        [sites, site, nearestSites],
      );
  </code></pre>
  <p>The error happening on the <code>.sort</code> part and the ´sortSiteSelection´ is as follow</p>
  <pre><code>const nameCompare = (x, y) =&gt; x.name.localeCompare(y.name);
  const cityCompare = (x, y) =&gt; x.city.localeCompare(y.city);
  const compareCountry = s =&gt; (x, y) =&gt; {
    if (!s) return 0;
  
    if (x.countryCode === s.countryCode &amp;&amp; y.countryCode === s.countryCode)
      return 0;
    else if (x.countryCode === s.countryCode) return -1;
    else if (y.countryCode === s.countryCode) return 1;
    else return x.countryCode.localeCompare(y.countryCode);
  };
  
  export const sortSiteSelection = selectedSite =&gt; {
    if (!selectedSite) {
      console.log('NULL FROM SORT SITE');
      return () =&gt; 0;
    }
    pipeSort(compareCountry(selectedSite), nameCompare, cityCompare);
  };
  </code></pre>
  <p>The OBJ of site is just</p>
  <pre><code>{
   siteId,
   city,
   elm.state,
   country,
   address,
   status,
  
  }
  </code></pre>