Why the join() methods is used for array? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why the join() methods is used for array?

22nd Aug 2019, 1:52 AM
Kensy Master Will
Kensy Master Will - avatar
4 Answers
+ 2
I'll assume you're referring to JavaScript's Array class/object's join method. ["It", "can", "do", "stuff", "like", "this."].join(" ") I use it mostly for converting arrays to human-readable strings. It compliments nicely with the split method which converts a string to an Array of strings. Converting between the 2 data structures makes it easier to take advantage of both string-features and Array-related features like map, filter, reduce, spreads, and other features of JavaScript when processing text information. In string format, it is easier to use regular expressions and in Array format, it is easier to use more general purpose tools.
22nd Aug 2019, 2:40 AM
Josh Greig
Josh Greig - avatar
+ 1
First Haitian Coder In Suriname Did you attempt to search for the basic documentation on this? I recommend reading MDN on Javascript basics. The ability to research the basics is critical to becoming a developer. Otherwise, you have a long, arduous road ahead with a massively steep learning curve in which you will be too dependent on others to overcome. Google Search: "Javascript join" Find the MDN link from the search results. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join Read first paragraph: ---- The join() method creates and returns a new string by concatenating all of the elements in an array (or an array-like object), separated by commas or a specified separator string. If the array has only one item, then that item will be returned without using the separator.
22nd Aug 2019, 2:56 AM
David Carroll
David Carroll - avatar
0
Why type of NaN is number and type of null is object
22nd Aug 2019, 2:53 AM
Kensy Master Will
Kensy Master Will - avatar
0
Thanks
22nd Aug 2019, 2:58 AM
Kensy Master Will
Kensy Master Will - avatar