javascript getting an array from an array in an object
<p>I have an object <code>MyObject</code> and one of its properties <code>ItemIDs</code> is an array of ints. I want to get a new array <code>PageItemIDs</code> that contains only part of the ints. It's for a pager; I pass in the page number <code>PageNumber</code> and I get the IDs of the items on the page. Suppose the page size is 20 items.</p>

<p>This is what I tried. It doesn't work because js works with references so I end up changing the array of the object.</p>

<pre class="lang-js prettyprint-override"><code>PageItemIDs = MyObject.ItemsID;
PageItemIDs = PageItemIDs.splice(PageNumber * 20, 20);
</code></pre>

<p>And instead of getting the ItemIDs in the page, I end up with the ItemIDs not in the page.</p>

<p>I know I'm not that far off but if you can help that'd be nice.</p>

<p>Thanks.</p>

<p>Edit:</p>

<p>When I do</p>

<pre><code>PageItemIDs = PageItemIDs.slice((PageNumber -1) * 20, 20);
</code></pre>

<p>it works for page 1 but for every other page, it returns an empty array.</p>

<p>Ok, I got it, nevermind.</p>

<pre><code> PageItemIDs = PageItemIDs.slice(PageNumber * 20, PageNumber * 20);
</code></pre>
