ArraySet()

In an one-dimensional array, sets the elements in a specified index range to a value.

Useful for initializing an array after a call to ArrayNew.

ArraySet( array=array, start_pos=number, end_pos=number, value=any );

Returns: Boolean

Argument Description
array
array, required

Name of an array.

start_pos
number, required

Starting index position of range to set.

Alias: start, startPos

end_pos
number, required

Ending index position of range to set. If this value is greater than array length, Lucee adds elements to array.

Alias: end, endPos

value
any, required

Value to which to set each element in the range.

Examples

Sets a range of array positions to a value

newArray = arrayNew(1);
<span class="nf">arraySet</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="s2">&quot;All is well&quot;</span><span class="p">);</span>
<span class="nf">dump</span><span class="p">(</span><span class="nv">newArray</span><span class="p">);</span>
<span class="c">// member function</span>
<span class="nf">newArray.set</span><span class="p">(</span><span class="m">1</span><span class="p">,</span><span class="m">2</span><span class="p">,</span><span class="s2">&quot;lets change it&quot;</span><span class="p">);</span>
<span class="nf">dump</span><span class="p">(</span><span class="nv">newArray</span><span class="p">);</span>

See also