# javaScript Array.join("")

**URL:** <https://forum.freecodecamp.org/t/javascript-array-join/568637>\
**Category:** Curriculum Help\
**Created:** [November 3, 2022, 4:23pm UTC](https://forum.freecodecamp.org/t/javascript-array-join/568637 "2022-11-03T16:23:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bisky0-0](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bisky0-0/32/241805_2.png) [@bisky0-0](https://forum.freecodecamp.org/u/bisky0-0)\
**Post date:** [November 3, 2022, 4:23pm UTC](https://forum.freecodecamp.org/t/javascript-array-join/568637/1 "2022-11-03T16:23:24Z")

</div>

hello,  
I have a problem here with `myArray.join("")`;  
why the first code work when writing `myArray.join("")` as a return statement and the second code doesn’t work without being a return statement?

```auto
const reverseString = function (string) {
    let myArray = string.split("");
    myArray.reverse();
    return myArray.join("");
};

```

```auto
const reverseString = function (string) {
    let myArray = string.split("");
    myArray.reverse();
    myArray.join("");
    return myArray;
};

```

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [November 3, 2022, 4:23pm UTC](https://forum.freecodecamp.org/t/javascript-array-join/568637/2 "2022-11-03T16:23:50Z")

</div>

Please post actual code instead of pictures. Thanks

* * *

> **[Array.prototype.join() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)**
>
> 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...

`.join()` does not mutate the array. It returns a new string that is created by joining the contents of the array.

---

<div class="post-metadata">

**Author:** ![bisky0-0](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bisky0-0/32/241805_2.png) [@bisky0-0](https://forum.freecodecamp.org/u/bisky0-0)\
**Post date:** [November 3, 2022, 4:34pm UTC](https://forum.freecodecamp.org/t/javascript-array-join/568637/3 "2022-11-03T16:34:58Z")

</div>

thank you so much;  
if there is reference for methods which mutate the array and others not please send a link, thanks again 🙏🏻

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [November 3, 2022, 4:36pm UTC](https://forum.freecodecamp.org/t/javascript-array-join/568637/4 "2022-11-03T16:36:44Z")

</div>

I just double check on MDN. I Google for “MDN methodname”, so here I searched “MDN array join”

---

<div class="post-metadata">

**Author:** ![bisky0-0](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bisky0-0/32/241805_2.png) [@bisky0-0](https://forum.freecodecamp.org/u/bisky0-0)\
**Post date:** [November 3, 2022, 4:43pm UTC](https://forum.freecodecamp.org/t/javascript-array-join/568637/5 "2022-11-03T16:43:34Z")

</div>

no i didn’t mean that,  
I mean I don’t know which methods mutate the original array and which not.  
when I was searching there’s no explination for that join(“”) “only return a new string” not mutate the array.  
so I’m asking for a reference which explain which methods change the original array and which only return new thing.

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [November 3, 2022, 4:48pm UTC](https://forum.freecodecamp.org/t/javascript-array-join/568637/6 "2022-11-03T16:48:51Z")

</div>

MDN will always have that information.

[Here it says](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)

> The **`join()`** method creates and returns a new string

[While for `splice` it says](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)

> The **`splice()`** method changes the contents of an array by removing or replacing existing elements and/or adding new elements [in place](https://en.wikipedia.org/wiki/In-place_algorithm)

So “creates and returns a new string” says nothing about changing the array, while “changes the contents of an array … in place” explicitly says that the array is mutated.

* * *

Learning how to read and understand documentation is a skill that takes a fair amount of practice.

---

<div class="post-metadata">

**Author:** ![bisky0-0](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bisky0-0/32/241805_2.png) [@bisky0-0](https://forum.freecodecamp.org/u/bisky0-0)\
**Post date:** [November 3, 2022, 5:09pm UTC](https://forum.freecodecamp.org/t/javascript-array-join/568637/7 "2022-11-03T17:09:58Z")

</div>

ok thank you so much;  
I’m really gratefull. 🙏🏻

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [May 5, 2023, 5:10am UTC](https://forum.freecodecamp.org/t/javascript-array-join/568637/8 "2023-05-05T05:10:23Z")

</div>

Closed on May 5, 2023, 5:10am UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
