ArraySlice()
Returns a new array, from the start position up to the count of elements
ArraySlice( array=array, offset=number, length=number );
Returns: Array
Argument | Description |
---|---|
array
array,
required
|
array to slice |
offset
number,
required
|
start position in the original array to slice |
length
number,
optional
|
number of elements to slice from offset |
Examples
Gets a sub section of an array and returns it
newArray = ['a','b','c','b','d','b','e','f'];
dump(newArray);
<span class="nv">hasSome1</span> <span class="o">=</span> <span class="nf">arraySlice</span><span class="p">(</span><span class="nv">newArray</span><span class="p">,</span><span class="m">1</span><span class="p">,</span><span class="m">4</span><span class="p">);</span>
<span class="nf">dump</span><span class="p">(</span><span class="nv">hasSome1</span><span class="p">);</span>
<span class="c">// member function</span>
<span class="nv">hasSome2</span> <span class="o">=</span> <span class="nf">newArray.slice</span><span class="p">(</span><span class="m">3</span><span class="p">,</span><span class="m">6</span><span class="p">);</span>
<span class="nf">dump</span><span class="p">(</span><span class="nv">hasSome2</span><span class="p">);</span>
See also
- Arrays
- array.slice()
- Search Issue Tracker
- Search Lucee Test Cases (good for further, detailed examples)