sorting object Sunday to Saturday in javascript
<p>Hello Everyone i know this question is asked several time but i am not getting exact answer to my question.</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>// I have array of object like this
data=[
        // "sunday": 1, // &lt;&lt; sunday is first day of week      
      {DayOfWeek:"Saturday", TotalCount:30},
      {DayOfWeek:"Friday", TotalCount:10},
      {DayOfWeek:"Monday", TotalCount:23},
      {DayOfWeek:"Sunday", TotalCount:18}, 
      {DayOfWeek:"Wednesday", TotalCount:20}        
    ];


// I need sorted like this:
data=[
        // "sunday": 1, // &lt;&lt; sunday is first day of week
      {DayOfWeek:"Sunday", TotalCount:18},  
      {DayOfWeek:"Monday", TotalCount:23},
      {DayOfWeek:"Wednesday", TotalCount:20},
      {DayOfWeek:"Friday", TotalCount:10},
      {DayOfWeek:"Saturday", TotalCount:30}  
    ];</code></pre>
</div>
</div>
</p>

<p>I tried this one but I am not able to get the expected result.
it is giving me a sorted array by starting alphabet like </p>

<p>Friday, Saturday.</p>

<blockquote>
  <p>var sorter = {
          // "sunday": 1, // &lt;&lt; sunday is first day of week
          "sunday": 1,
          "monday": 2,
          "tuesday": 3,
          "wednesday": 4,
          "thursday": 5,
          "friday": 6,
          "saturday": 7
        }</p>
</blockquote>

<pre><code>  var result= data.sort(function sortByDay(a, b) {
    var day1 = a.DayOfWeek.toLowerCase();
    var day2 = b.DayOfWeek.toLowerCase();
    return sorter[day1] &gt; sorter[day2];
  });
</code></pre>

<p>Please help me, Thanks in advance.</p>