Combine Values of an Array into a String with Join

Share this video with your friends

Send Tweet

The join() method joins all elements of an array into a string. In this lesson we first look at why join is often a better option than regular string concatenation. Then we move onto an example which shows a simple way of storing lines of text in an array and outputting them with a new line separator and we finish by looking at ways to chain multiple array methods together.

Jason
Jason
~ 9 years ago

I am a little confused with the .map syntax. I understand what it is doing, but have never seen that syntax before.

.map(x => x.charAt(0).toUpperCase + x.slice(1))

what does the "x =>" do? Is that like saying x is greater than or equal to (x >=)?

Joel Hooks
Joel Hooks
~ 9 years ago

I am a little confused with the .map syntax. I understand what it is doing, but have never seen that syntax before.

.map(x => x.charAt(0).toUpperCase + x.slice(1))

what does the "x =>" do? Is that like saying x is greater than or equal to (x >=)?

This is the same as:

.map(function(x) {
  return x.charAt(0).toUpperCase + x.slice(1)
});

=> is the ECMAScript 6 arrow function operator. https://egghead.io/lessons/arrow-function