# Retrieve items from an array

**URL:** <https://forum.kirupa.com/t/retrieve-items-from-an-array/253981>\
**Category:** Uncategorized\
**Created:** [March 6, 2008, 11:44pm UTC](https://forum.kirupa.com/t/retrieve-items-from-an-array/253981 "2008-03-06T23:44:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ariff](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@Ariff](https://forum.kirupa.com/u/Ariff)\
**Post date:** [March 6, 2008, 11:44pm UTC](https://forum.kirupa.com/t/retrieve-items-from-an-array/253981/1 "2008-03-06T23:44:14Z")

</div>

Hi,

got the following question for you guys :

var testArray:Array = new Array(“mc0”,“mc1”,“mc2”,“mc3”,“mc4”,“mc5”,“mc6”,“mc7”,…);  
var page:int = 1  
var itemsPerPage:int = 2

function PageSelect(page:int, itemsPerPage:int){  
}

i need to find out how i can select items from the array considering the 2 vars that are given.

in this example the function PageSelect(1,2) should return mc2 & mc3

page = 1 & itemsPerPage = 2

page 0 = mc0 & mc1  
page 1 = mc2 & mc3  
page 2 = mc4 & mc5  
page 3 = …  
…

in case page = 2 and itemsPerPage = 3

page 0 = mc0 & mc1 & mc2  
page 1 = mc3 & mc4 & mc5  
page 2 = mc6 & mc7 & mc8

im trying to write a function which accepts those 2 variables and returns the correct mc’s from the array.

really hope someone can give me a hint in the good direction. Tried using the array.slice method but i didnt manage to get the correct results or partially correct results.

im sorry if this is not very clear, but im not a native english speaker/writer, so it’s not easy to explain. My appologies for that !

thanks again !  
Ariff

i searched a bit more and found the following solution :

if i would slice the array like this :

array.slice(page_recordsPerPage, (page_recordsPerPage) + recordsPerPage)

i think that would give me the correct solution
