Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>1) Using <strong><code>$.each()</code></strong> iterate the parsed JSON.<br> 2) To get the week number use the below <a href="https://stackoverflow.com/a/20046599/1671639">protype method</a></p> <pre><code>Date.prototype.getWeek = function () { var onejan = new Date(this.getFullYear(), 0, 1); return Math.ceil((((this - onejan) / 86400000) + onejan.getDay() + 1) / 7); } </code></pre> <p>To use:</p> <pre><code>var todayWeekNo = new Date().getWeek(); </code></pre> <p>3)To check whether they belong to same week use</p> <pre><code>var isEqual = (todayWeekNo == new Date(j.Date).getWeek()); </code></pre> <p>4) If it is not equal, delete it using index.</p> <p>Finally,</p> <pre><code>Date.prototype.getWeek = function () { var onejan = new Date(this.getFullYear(), 0, 1); return Math.ceil((((this - onejan) / 86400000) + onejan.getDay() + 1) / 7); } var arr = [{ "StudentID": 5041, "Status": "Joshua picked up from school [0] at 12:41PM and reached home [0] at 12:43PM", "Date": "2013-11-20" }, { "StudentID": 5042, "Status": "Joshua picked up from school [0] at 12:41PM and reached home [0] at 12:43PM", "Date": "2013-11-20" }, { "StudentID": 5043, "Status": "Joshua picked up from school [0] at 12:41PM and reached home [0] at 12:43PM", "Date": "2013-11-20" }]; var todayWeekNo = new Date().getWeek(); $.each(arr, function (i, j) { var isEqual = todayWeekNo == new Date(j.Date).getWeek(); if (!isEqual) { delete arr[i]; } }); </code></pre> <h2><a href="http://jsfiddle.net/h6hte/" rel="nofollow noreferrer">JSFiddle</a></h2> <p><strong>Updates:</strong></p> <blockquote> <p><a href="https://stackoverflow.com/a/500617/1671639">Since <code>Delete</code> won't remove the element from the array it will only set the element as <code>undefined</code>.</a></p> </blockquote> <p>So I tried using <strong><code>arr.splice(i, 1);</code></strong> but it was not working. With reference to this <a href="https://stackoverflow.com/q/20125989/1671639">question</a> here is an alternative approach.</p> <pre><code>var todayWeekNo = new Date().getWeek(); for (var i = 0; i &lt; arr.length;) { var isEqual = (todayWeekNo == new Date(arr[i].Date).getWeek()); if (!isEqual) { arr.splice(i, 1); } else { i++; } } </code></pre> <p>Hope you understand.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload