What is array join in javascript?

 array join method javascript:


join() method means converting an array into a string but we can add between an array element with separator as like you want:, * space or something you like.

Syntax of join method:


If we are using without any customize separator then it's added by default with (comma), separator.


Join example in javascript:


const colors = ["Red", "blue", "Black", "Orange", "White", "Coffee"];



// By default: "Red,blue,Black,Orange,White,Coffee"



// without any space:  "RedblueBlackOrangeWhiteCoffee"



// with star: "Red*blue*Black*Orange*White*Coffee"


console.log(colors.join(' - '));

// with dash: "Red - blue - Black - Orange - White - Coffee"

No comments:

Note: Only a member of this blog may post a comment.

Copyright Reserved to Anything Learn. Powered by Blogger.