Skip to content
Related Articles

Related Articles

Improve Article
Collect.js join() Method
  • Last Updated : 27 Nov, 2020

The join() method is used to join the collection elements with given string and returns the collection elements.

Syntax:

collect(array).join()

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

Return Value: This method joins the collection elements with given string and returns the values.

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



Example 1:




const collect = require('collect.js');
  
let arr1 = [10, 20, 30, 40, 50];
  
const collection1 = collect(arr1);
  
console.log(collection1.join(', '));
  
let arr2 = ['a', 'b', 'c', 'd'];
  
const collection2 = collect(arr2);
  
console.log(collection2.join(', ', ' and '));

Output:

10, 20, 30, 40, 50
a, b, c and d

Example 2:




const collect = require('collect.js');
  
let arr = ['Geeks', 'GFG', 'GeeksforGeeks'];
  
const collection = collect(arr);
  
console.log(collection.join(', '));

Output:

Geeks, GFG, GeeksforGeeks
My Personal Notes arrow_drop_up
Recommended Articles
Page :