Open In App

How to push elements in an array using AngularJS ?

Last Updated : 09 Aug, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Given an array and the task is to perform the push operation on the array using AngularJS. The arr.push() method is used to push one or more values into the array, & new values will add at the end of an array. This method changes the length of the array by the number of elements added to the array & returns the new length of the modified array.

Syntax:

arr.push(element1, elements2 ....., elementN]])

Approach: In this approach, the push() method is used to insert the element at the end of the array. In the first example, a static value 'Geek' is inserted in the array, and in the second example, an input box is provided to the user to push the value they want.

Example 1: In this example, we will push the "Geek" & add the new element to the array arr.

Output:

 

Example 2: This example describes the addition of a new element to an array to the array list by specifying the value in the input section.

Output:

 

Next Article

Similar Reads