The Wayback Machine - https://web.archive.org/web/20240828170718/https://www.geeksforgeeks.org/node-js-push-function/
Open In App

Node.js push() function

Last Updated : 30 Mar, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

push() is an array function from Node.js that is used to add elements to the end of an array. 

Syntax:

array_name.push(element)

Parameter: This function takes a parameter that has to be added to the array. It can take multiple elements also. 

Return type: The function returns the array after adding the element. The program below demonstrates the working of the function: 

Program 1: 

javascript




function PUSH() {
    arr.push(2);
    console.log(arr);
}
const arr = [12, 3, 4, 6, 7, 11];
PUSH();


Output:

[ 12,  3, 4, 6, 7, 11, 2]

Program 2: 

javascript




function addLang() {
    arr.push('DS', 'Algo', 'JavaScript');
    console.log(arr);
}
const arr = ['NodeJs'];
addLang();


Output:

[ 'NodeJs', 'DS', 'Algo', 'JavaScript' ]

Program 3: 

javascript




const Lang = ['java', 'c', 'python'];
 
console.log(Lang);
// expected output: Array [ 'java', 'c', 'python' ]
 
Lang.push('node');
 
console.log(Lang);
// expected output: Array [ 'java', 'c', 'python', 'node' ]


Output:

[ 'java', 'c', 'python' ]
[ 'java', 'c', 'python', 'node' ]


Similar Reads

Difference Between Git Push Origin and Git Push Origin Master
Understanding the difference between git push origin and git push origin master is important for efficient version control in Git. These commands are used to upload changes from your local repository to a remote repository, but they function differently. This article will explain these differences, how each command works, and when to use them. What
3 min read
How to Push Data to Array Asynchronously & Save It in Node.js ?
Node.js is a powerful environment for building scalable and efficient applications, and handling asynchronous operations is a key part of its design. A common requirement is to collect data asynchronously and store it in an array, followed by saving this data persistently, for instance, in a database or a file. This article explores the techniques
6 min read
PHP | Ds\Sequence push() Function
The Ds\Sequence::push() function is an inbuilt function in PHP which adds values to the end of the sequence. Syntax: void abstract public Ds\Sequence::push( $values ) Parameters: This function accepts single parameter $values which contains one or more values. It hold the value to be added in the sequence. Return value: This function does not retur
2 min read
PHP | Ds\Vector push() Function
The Ds\Vector::push() function is an inbuilt function in PHP that is used to add elements to the end of the vector. Syntax: void public Ds\Vector::push( $values ) Parameters: This function accepts a single parameter $values which contains one or more than one element to be added to the vector. Return Value: This function does not return any values.
2 min read
PHP | Ds\Deque push() Function
The Ds\Deque::push() function is an inbuilt function in PHP which is used to add the elements to the Deque by appending an element at the end of the Deque. Syntax: public Ds\Deque::push( $values ) : void Parameters: This function accepts single parameter $values which holds the elements to be added to the Deque. Return Value: This function does not
2 min read
PHP | Ds\Stack push() Function
The Ds\Stack::push() function of PHP is used to add elements at the end of the stack. That it is used to push elements on to a stack. The elements being pushed can be of mixed data types. Syntax: void public Ds\Stack::push ($values) Parameter: This function accepts a single parameter $values which is used to push onto the stack. Return Value: This
1 min read
PHP Ds\PriorityQueue push() Function
The Ds\PriorityQueue::push() Function in PHP is used to push or insert values in a PriorityQueue instance. This function pushes values along with a given priority in the PriorityQueue. Syntax: void public Ds\PriorityQueue::push($value, $priority) Parameters: This function accepts two parameters: $value: This is the value to be inserted in the Prior
1 min read
PHP Ds\Queue push() Function
The Ds\Queue::push() Function in PHP is used to push or insert values in a PriorityQueue instance. This function can also insert a list of values directly to the Queue. Syntax: void public Ds\Queue::push($value1, $value2, .... $valueN) Parameters: This function accepts a list of values separated by spaces as parameter. All of these values are pushe
1 min read
PHP SplDoublyLinkedList push() Function
The SplDoublyLinkedList::push() function is an inbuilt function in PHP which is used to push an element at the end of the doubly linked list. Syntax: void SplDoublyLinkedList::push( $value ) Parameters: This function accepts a single parameter $value which holds an element to push it at the end of doubly linked list. Return Value: It does not retur
1 min read
Collect.js | push() Function
The push() function is used to add a new value to the end of the collection. In JavaScript, the array is first converted to a collection and then the function is applied to the collection. Syntax: data.push(value) Parameters: This function accepts a single parameter as mentioned above and described below: value: This parameter holds the value to be
1 min read
Backbone.js push Collection
In this article, we will see the Backbone.js push Collection. The Backbone.js push Collection can be utilized to add the model to the collection's end i.e. it simply pushes the model to the collection. Syntax: collection.push(models, options) Parameters: It will take 2 parameters, which are described below: models: This parameter value is used to s
3 min read
Sending Push Notifications : Progressive Web Apps
We need permissions to send push notifications. Key Points : Notifications must be timely. Should be precise (contains all the information a user needs). Should be relevant to the user. Basic Example : An airline app must send push notifications such as "Your flight will be boarding from..." Browser that supports push notifications are : Chrome 44
3 min read
p5.js | Push Operation on Stack
What is Stack? The stack is a linear data structure like an array in which only the last inserted element can be accessed. This data structure works over the principle of Last In First Out (LIFO). It is very fast since it has to access only the last added element so it requires constant time to do so having complexity O(1). Stacks should be used ov
3 min read
How to push an array into the object in JavaScript ?
In order to push an array into the object in JavaScript, we need to utilize the push() function. With the help of Array push function this task is so much easy to achieve. push() function: The array push() function adds one or more values to the end of the array and returns the new length. This method changes the length of the array. But here we wi
2 min read
Alternatives of push() method in JavaScript
The task is to perform a push operation without using the push() method with the help of JavaScript. There are two approaches that are discussed below. Approach 1: Use the length property to insert the element at the end of the array. Example: This example implements the above approach. C/C++ Code <body style="text-align: center;">
2 min read
How to use .join() with push and replace together?
Array.join() MethodThe array.join() method is an inbuilt function in JavaScript which is used to join the elements of an array into a string.The elements of the string will be separated by a specified separator and its default value is comma (, ). Syntax: array.join(separator) Array.push() Method The array.push() function is used to push one or mor
2 min read
How to push elements in an array using AngularJS ?
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 ar
2 min read
What is the difference between unshift() and Push() method in JavaScript?
JavaScript Unshift() method is very much similar to the push() method but the difference is that the unshift() method adds the elements at the very beginning of the array whereas the push() method adds at the end of the array. Javascript Array unshift() method: The JavaScript Array unshift() Method is used to add one or more elements to the beginni
2 min read
How to push data in a MongoDB document ?
The insertOne() and insertMany() are the two methods of the MongoDB module in node.js that are used to push the documents in the collections of the MongoDB database. The insertOne() method inserts one data at a time into the collection and insertMany() method inserts multiple data into the collection of the MongoDB database. In this article, we wil
2 min read
Semantic-UI Sticky Push
Semantic UI open-source framework gives icons or glyphs that are used to show pictures related to some elements using CSS and jQuery that is used to create great user interfaces. It is a development framework used to create beautiful and responsive layouts. Semantic UI Sticky content remains fixed to the browser viewport until another content on th
2 min read
React Suite Grid Push and Pull
A React suite is a library of React components, sensible UI design, and a friendly development experience. It is supported in all major browsers. It provides pre-built components of React which can be used easily in any web application. In this article, we'll learn about React suite Grid Push and Pull. The grid push and pull are used to change the
5 min read
React Suite Notification toaster.push Method
React Suite is a library of React components, sensible UI design, and a friendly development experience. It is supported in all major browsers. It provides pre-built components of React which can be used easily in any web application. In this article, we'll learn about React Suite Notification toaster.push() method. This method is basically used to
3 min read
How to send push notification using XMPP Server?
In this article, we are going to learn how can we send push notifications using the XMPP server. XMPP stands for extensible Messaging and Presence Protocol and it is a free open-source, cross-platform web server solution stack package. which is easy to install and contains mainly the Apache HTTP Server, and MariaDB database, and it is written in pr
2 min read
How to add push notification feature in React JS ?
Push notifications are used to inform users about updates, messages, or events within your web application. In ReactJS, push notifications can be integrated using service workers and the Notifications API. Prerequisite: Introduction and installation of React JSReact-hook useStateIn this article, we will learn how to add a push-on notification featu
2 min read
What is the use of the push() method in JavaScript Arrays ?
In JavaScript, the push() method is used to add one or more elements to the end of an array. It modifies the original array by appending the specified values. This can be particularly useful when you want to dynamically expand the size of an array or simply add new elements to the existing list. Example: Here, we are pushing newElement in myArray.
1 min read
How to Push an Object into an Array using For Loop in JavaScript ?
JavaScript allows us to push an object into an array using a for-loop. This process consists of iterating over the sequence of values or indices using the for-loop and using an array manipulation method like push(), to append new elements to the array. We have given an empty array, and we need to push the object into the array. Below is an example
3 min read
How to Push Item From an Array in Mongoose ?
In Mongoose, pushing an item to an array can be done using different approaches. To push an item into an array, you can use the $push operator along with the updateOne() or updateMany() method. We will discuss the different methods to push items from an array in Mongoose: Table of Content Inserting a new document Using $push OperatorUsing addToSet
4 min read
Push Codes from Linux (UBUNTU) To GitHub using SSH KEY
GitHub, one of the most popular platforms for version control and collaboration, offers multiple authentication methods for interacting with repositories. SSH keys provide a secure and convenient way to authenticate and push code from a local machine to GitHub. In this article, we'll learn the step-by-step process of pushing code from Linux (Ubuntu
3 min read
How to Push Folders From Local PC to GitHub using Git Commands?
Git offers a powerful command-line interface for managing code repositories, understanding how to push folders from your local PC to GitHub repositories using Git commands can enhance your workflow and streamline the process of sharing code with collaborators or deploying projects. In this article, we'll see the step-by-step process of pushing fold
2 min read
How to Push Git Tags to Remote Repository?
Git tags are references to specific points in Git history and are used to mark release points (like version numbers). Pushing Git tags to a remote repository is important for sharing these release points with collaborators or deploying releases to production environments. In this article, we'll explore the process of pushing Git tags to a remote re
3 min read