Adding and removing objects to an array
7.5: Adding and Removing Objects - p5.js Tutorial
Code for this tutorial
Removing Objects from an Array
Pop = takes last item off the end of the array (Last in, first out)
Find out what other commands are in Javascript.
Push = appends a value to the end of the array; extends the size of the array by 1.
Splice(index, how many) = allows you to take stuff out of the array. Index = first item to delete.
When deleting elements from an array, be sure to change your for() command to start at the end of your array and go backwards, down to 0.
Code for this tutorial
Removing Objects from an Array
Pop = takes last item off the end of the array (Last in, first out)
Find out what other commands are in Javascript.
Push = appends a value to the end of the array; extends the size of the array by 1.
Splice(index, how many) = allows you to take stuff out of the array. Index = first item to delete.
When deleting elements from an array, be sure to change your for() command to start at the end of your array and go backwards, down to 0.