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, zambiatek 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!



