0 day streak
javascript / beginner
Snippet

Managing Lists with Array.push

JavaScript arrays come with built-in methods. The push() method adds a new item to the end of an array, allowing you to dynamically update lists.

snippet.js
javascript
1
2
3
4
5
6
7
export class TaskListComponent {
tasks = ['Read', 'Code'];
addTask(name) {
this.tasks.push(name);
}
}
angular
Breakdown
1
this.tasks.push(name)
Adds the value stored in the 'name' variable to the 'tasks' array.