PICO-8 Wiki
Tag: Visual edit
(helps to pay attention to the actual goal)
Tag: Source edit
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
  +
{{ApiReference
<span style="font-weight: bold"></span><span style="font-weight: bold">deli</span>( tbl, i )
 
  +
|name=deli
: Deletes the first occurrence of a value from a sequence in a table.
 
  +
|shortdesc=Removes the element at the given index of a sequence in a table.
: tbl<span style="font-weight: normal;"></span>
 
  +
|tbl||The table.
  +
|i||The index for the value to be removed.
  +
}}
   
:: <span style="font-weight: normal;">The table. </span>
 
: i
 
;;;;;;;;;;;;;;;;;;;;:<span style="font-weight: normal;">The value to match and remove. </span>
 
;;;;;:
 
 
The deli() function removes the value at the given index of a sequence. All subsequent values in the sequence shift down by one slot to keep the sequence contiguous.
 
The deli() function removes the value at the given index of a sequence. All subsequent values in the sequence shift down by one slot to keep the sequence contiguous.
   
Line 17: Line 16:
 
</syntaxhighlight>
 
</syntaxhighlight>
 
==See also==
 
==See also==
  +
* [[Lua]]
*[https://pico-8.fandom.com/wiki/Lua Lua]
 
  +
* [[Tables]]
*[https://pico-8.fandom.com/wiki/Tables Tables]
 
  +
* <code>[[Add|add()]]</code>
*[https://pico-8.fandom.com/wiki/Add add()]
 
  +
* <code>[[Del|del()]]</code>
*[https://pico-8.fandom.com/wiki/All all()]
 
  +
* <code>[[All|all()]]</code>
*[https://pico-8.fandom.com/wiki/Foreach foreach()]
 
  +
* <code>[[Foreach|foreach()]]</code>
*[https://pico-8.fandom.com/wiki/Pairs pairs()]
 
  +
* <code>[[Pairs|pairs()]]</code>
[[Category:Reference, API]]
+
[[Category:Reference]]
  +
[[Category:API]]

Revision as of 20:37, 11 March 2021

deli( tbl, i )
Removes the element at the given index of a sequence in a table.
tbl
The table.

i
The index for the value to be removed.

The deli() function removes the value at the given index of a sequence. All subsequent values in the sequence shift down by one slot to keep the sequence contiguous.

The deli() function returns the object being removed. This can be ignored, tested it to see if the removal was successful, or used as needed.

Example

t = {1, 2, 4, 3, 4}
deli(t, 5)  -- t = {1, 2, 4, 3}
deli(t, 3)  -- t = {1, 2, 3}

See also