Saturday, July 4, 2026
HomeLanguagesJavascriptCollect.js | push() Function

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 added.

Return Value: Returns a modified collection which is created by this function.

Below examples illustrate the push() function in collect.js
Example 1:

Javascript




// It is used to import collect.js library
const collect = require('collect.js');
  
const collection = collect(["Geeks", "for", "Geeks"]);
collection.push("CS");
console.log(collection.all());


Output: 

[ 'Geeks', 'for', 'Geeks', 'CS' ]

Example 2:

Javascript




// It is used to import collect.js library
const collect = require('collect.js');
  
const collection = collect([10 , 20 , 30]);
collection.push(40);
console.log(collection.all());


Output: 

[ 10, 20, 30, 40 ]

Reference: https://collect.js.org/api/push.html

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32519 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6900 POSTS0 COMMENTS
Nicole Veronica
12015 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12110 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6967 POSTS0 COMMENTS