# Array question making array based on selected index or element

**URL:** <https://forum.kirupa.com/t/array-question-making-array-based-on-selected-index-or-element/281791>\
**Category:** Uncategorized\
**Created:** [February 13, 2009, 8:01am UTC](https://forum.kirupa.com/t/array-question-making-array-based-on-selected-index-or-element/281791 "2009-02-13T08:01:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cosmicloverocks](https://avatars.discourse-cdn.com/v4/letter/c/dfb087/32.png) [@cosmicloverocks](https://forum.kirupa.com/u/cosmicloverocks)\
**Post date:** [February 13, 2009, 8:01am UTC](https://forum.kirupa.com/t/array-question-making-array-based-on-selected-index-or-element/281791/1 "2009-02-13T08:01:17Z")

</div>

How can i make new array selecting an index :  
let say i have an array like this:

var myarray: Array = [“a”, “b”,“c”, “d”,“e”, “f”, “g” ,“h”, “i”, “j” , “k” , “l”];

and let say i selected **myarray[4]** or \*\*“e” \*\* so when i point it to “e” then the 3 elements before that will get selected and also the 3 elements after that …so it will form something like this …

newarray = [“b” , “c” ,“d” , **“e”** , “f” ,“g” , “h”];

or let say i selected **myarray[7]** which is the **“h”** then  
the newarray = [“e”, “f”, “g”, **“h”** , “i”, “j”, “k”];

and so on … hopes this is clear. …

basicly just make new array according to the selected or current index …

another example if **myarray[0]** is selected

then the newarray = [**“a”** , “b”,“c” , “d”] the 3 before that will not be created since there is none same goes at the end of an array …

thanks in advanced…
