Category: Variables
Appends the item to the end of the array.
In real life you sometimes need add items to the end of the list, and make the list larger. appendItem(list, item) makes the "list" one larger and inserts the "item" at the end of the list. If the append is successful, appendItem() returns true, otherwise it returns false.
// List of favorite movies. var myFavoriteMovies=[]; appendItem(myFavoriteMovies, "Star Wars"); appendItem(myFavoriteMovies, "Lord of the Rings"); appendItem(myFavoriteMovies, "Harry Potter"); console.log(myFavoriteMovies);
Example: Fibonacci Generate the first 10 numbers in the fibonacci sequence.
// Generate the first 10 numbers in the fibonacci sequence. var fibonacci=[1,1]; var nextTerm=0; for (var i=3; i<=10; i++) { nextTerm=fibonacci[i-2]+fibonacci[i-3]; appendItem(fibonacci,nextTerm); } console.log(fibonacci);
appendItem(list, item)
Name | Type | Required? | Description |
---|---|---|---|
list | variable name | Yes | The variable name of the list (array) you want to append to the end of. |
item | any type | Yes | The number or string item to be inserted at the end of the list. |
Boolean true or false
Found a bug in the documentation? Let us know at documentation@code.org
appendItem(list, item)
Found a bug in the documentation? Let us know at documentation@code.org