mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 22:28:45 +01:00
Deploy to GitHub Pages:
This commit is contained in:
15
lists.html
15
lists.html
@ -202,19 +202,28 @@ System.print(combined) //> [a, b, c, d, e, f]
|
||||
|
||||
<h2>Removing elements <a href="#removing-elements" name="removing-elements" class="header-anchor">#</a></h2>
|
||||
<p>The opposite of <code>insert</code> is <code>removeAt</code>. It removes a single element from a
|
||||
given position in the list. All following items are shifted up to fill in the
|
||||
gap:</p>
|
||||
given position in the list. </p>
|
||||
<p>To remove a specific <em>value</em> instead, use <code>remove</code>. The first value that
|
||||
matches using regular equality will be removed.</p>
|
||||
<p>In both cases, all following items are shifted up to fill in the gap.</p>
|
||||
<pre class="snippet">
|
||||
var letters = ["a", "b", "c", "d"]
|
||||
letters.removeAt(1)
|
||||
System.print(letters) //> [a, c, d]
|
||||
letters.remove("a")
|
||||
System.print(letters) //> [c, d]
|
||||
</pre>
|
||||
|
||||
<p>The <code>removeAt</code> method returns the removed item:</p>
|
||||
<p>Both the <code>remove</code> and <code>removeAt</code> method return the removed item:</p>
|
||||
<pre class="snippet">
|
||||
System.print(letters.removeAt(1)) //> c
|
||||
</pre>
|
||||
|
||||
<p>If <code>remove</code> couldn’t find the value in the list, it returns null:</p>
|
||||
<pre class="snippet">
|
||||
System.print(letters.remove("not found")) //> null
|
||||
</pre>
|
||||
|
||||
<p>If you want to remove everything from the list, you can clear it:</p>
|
||||
<pre class="snippet">
|
||||
hirsute.clear()
|
||||
|
||||
@ -146,6 +146,23 @@ System.print(["a", "c"].insert(1, "b")) //> b
|
||||
<h3><strong>iterate</strong>(iterator), <strong>iteratorValue</strong>(iterator) <a href="#iterate(iterator),-iteratorvalue(iterator)" name="iterate(iterator),-iteratorvalue(iterator)" class="header-anchor">#</a></h3>
|
||||
<p>Implements the <a href="../../control-flow.html#the-iterator-protocol">iterator protocol</a> for iterating over the elements in the
|
||||
list.</p>
|
||||
<h3><strong>remove</strong>(value) <a href="#remove(value)" name="remove(value)" class="header-anchor">#</a></h3>
|
||||
<p>Removes the first value found in the list that matches the given <code>value</code>,
|
||||
using regular equality to compare them. All trailing elements
|
||||
are shifted up to fill in where the removed element was.</p>
|
||||
<pre class="snippet">
|
||||
var list = ["a", "b", "c", "d"]
|
||||
list.remove("b")
|
||||
System.print(list) //> [a, c, d]
|
||||
</pre>
|
||||
|
||||
<p>Returns the removed value, if found.
|
||||
If the value is not found in the list, returns null.</p>
|
||||
<pre class="snippet">
|
||||
System.print(["a", "b", "c"].remove("b")) //> b
|
||||
System.print(["a", "b", "c"].remove("not found")) //> null
|
||||
</pre>
|
||||
|
||||
<h3><strong>removeAt</strong>(index) <a href="#removeat(index)" name="removeat(index)" class="header-anchor">#</a></h3>
|
||||
<p>Removes the element at <code>index</code>. If <code>index</code> is negative, it counts backwards
|
||||
from the end of the list where <code>-1</code> is the last element. All trailing elements
|
||||
|
||||
Reference in New Issue
Block a user