Wednesday, July 3, 2024
HomeLanguagesJavascriptCollect.js implode() Method

Collect.js implode() Method

The implode() method is used to join the given items into the collection.

Syntax:

collect(array).implode(join_key)

Parameters: The collect() method takes one argument that is converted into the collection and then implode() method is applied on it. The implode() method holds the value of join key.

Return Value: This method returns the collection items using given join key.

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

Example 1:




const collect = require('collect.js');
  
let arr = [10, 20, 30, 40, 50];
  
const collection = collect(arr);
  
const implode_val = collection.implode(', ');
  
console.log(implode_val);


Output:

10, 20, 30, 40, 50

Example 2:




const collect = require('collect.js');
  
let obj = [
    {
        name: 'Rahul',
        dob: '25-10-96',
        section: 'A',
        score: 98,
    },
    {
        name: 'Aditya',
        dob: '25-10-96',
        section: 'B',
        score: 96,
    },
    {
        name: 'Abhishek',
        dob: '16-08-94',
        section: 'A',
        score: 80
    },
    {
        name: 'Rahul',
        dob: '19-08-96',
        section: 'B',
        score: 77,
    },
];
  
const collection = collect(obj);
  
const implode_val = collection.implode('name', ', ');
  
console.log(implode_val);


Output:

Rahul, Aditya, Abhishek, Rahul

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 Rubhabha Wardslaus
Dominic Rubhabha Wardslaushttps://neveropen.dev
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments