Thursday, September 4, 2025
HomeLanguagesJavascriptCollect.js put() Method

Collect.js put() Method

The put() method is used to set the given key and value in the collection.

Syntax:

collect(array).put(key)

Parameters: The collect() method takes one argument that is converted into the collection and then put() method is applied on it. The put() method holds the key as parameter.

Below example illustrate the put() method in collect.js:

Example 1:

Javascript




const collect = require('collect.js');
 
let obj = ['Geeks', 'GFG', 'neveropen'];
 
const collection = collect(obj);
 
collection.put('Welcome');
 
console.log(collection.all());


Output:

[ 'Geeks', 'GFG', 'neveropen', Welcome: undefined ]

Example 2:

Javascript




const collect = require('collect.js');
 
let obj = {
    name: 'Rahul',
    dob: '25-10-96',
    section: 'A',
    score: 98,
};
 
const collection = collect(obj);
 
collection.put(['Welcome to neveropen']);
 
console.log(collection.all());


Output:

{
  name: 'Rahul',
  dob: '25-10-96',
  section: 'A',
  score: 98,
  'Welcome to neveropen': undefined
}
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!
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6629 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11859 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6717 POSTS0 COMMENTS