---
title: "Discussion on \"Why the with() method of JavaScript Array is a gem?\" | Hashnode"
description: "Discussion on \"Why the with() method of JavaScript Array is a gem?\". Discover the new with() method in JavaScript Arrays from ECMAScript 2023 with examples and use cases."
url: "https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Why the with() method of JavaScript Array is a gem?](https://blog.greenroots.info/javascript-array-method-with-immutability?utm_source=hashnode&utm_medium=feed)

Discover the new with() method in JavaScript Arrays from ECMAScript 2023 with examples and use cases.

Jul 8, 2024 · 5 min read · blog.greenroots.info  
Updated Jul 11, 2024  
Read the article

-   [#programming](https://hashnode.com/tag/programming)
-   [#beginners](https://hashnode.com/tag/beginners)
-   [#javascript](https://hashnode.com/tag/javascript)
-   [#codenewbies](https://hashnode.com/tag/codenewbies)
-   [#array](https://hashnode.com/tag/array)

## Written by

[Tapas Adhikary](https://hashnode.com/@atapas)

@atapas · Bangalore

  
[View profile](https://hashnode.com/@atapas)

Educator @tapaScript | Founder CreoWis & ReactPlay - Writer - YouTuber - Open Source

Co-Founder, @CreoWis | Teacher, @tapaScript | Founder, @ReactPlay | YouTuber | Writer | Human

## Responses 17

Markdown supported · ⌘↵ to post

[francisco loyola](https://hashnode.com/@fcolm)

[Oct 8, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/670588dba8e4982fbaa25cee)

Can it be used in a project such as Angular +11 ?

[Geta Spoon](https://hashnode.com/@celine1234)

[Sep 23, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/66f116cd273dae4811c81ba1)

really useful, appreciate

[USB Restore](https://hashnode.com/@usbrestore)

[Sep 18, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/66eabb0153159e8da803fc64)

Thank you for this information!

[JHK Infotech](https://hashnode.com/@himanshu0220)

[Sep 12, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/66e2c46c004a2a333bcc91cf)

Immutable Updates: It creates a new array without altering the original, making it useful in state management. Readability: It provides a clean and concise syntax for updating elements at specific indexes. Safer: Since it doesn’t mutate the original array, it reduces the risk of side effects in your code. let arr = \[1, 2, 3\]; let newArr = arr.with(1, 5); // \[1, 5, 3\] console.log(arr); // Original array remains \[1, 2, 3\]

[Andrew Baisden](https://hashnode.com/@andrewbaisden)

[Sep 10, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/66e0446b99f0453ff9148a8f)

Another helpful method. Thanks for sharing.

[Tapas Adhikary](https://hashnode.com/@atapas)

[Sep 12, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/66e0446b99f0453ff9148a8f#reply-66e26b3760e3956557e38e15)

Thank you [Andrew Baisden](https://hashnode.com/@andrewbaisden). Appreciate it

[Jackson David](https://hashnode.com/@jackson943)

[Aug 13, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/66baee0190ea1057a46fdf8c)

i live in Canada a friend introduces me to blank atm card which i got from Davidwilson hackers, i believe him so well not like scammers out there i have withdrew $50000 with this card so i decided to share a testimony if you are interested contact him now for Financial Solutions Davidwilson2284@gmail.com

[David Williford](https://hashnode.com/@DavidWilliford)

[Aug 9, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/66b60c1acf25bdc1e7438d92)

I like how it allows you to use negative indexes. I'm surprised this is not already a feature in javascript.

[Tapas Adhikary](https://hashnode.com/@atapas)

[Aug 9, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/66b60c1acf25bdc1e7438d92#reply-66b60d22e3d019c779041add)

Thank you [David Williford](https://hashnode.com/@DavidWilliford)

[byteDev](https://hashnode.com/@byteDev)

[Jul 17, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/6697ccf60d10fa8bba9824ae)

Wow, this Method is can be quick use snippet, thanks, keep writing

[Tapas Adhikary](https://hashnode.com/@atapas)

[Jul 17, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/6697ccf60d10fa8bba9824ae#reply-6697ed19a36d6716a6649450)

Thank you [byteDev](https://hashnode.com/@byteDev)

[Benjamin Rensch Vinterberg](https://hashnode.com/@JuicyBenjamin)

[Jul 17, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/66978a2a9ed675a1c10bc2c1)

I did not know this existed, thank you for the blog post. While I have no use case for this ( for now at least ) I always love learning more about the language I use as my daily driver.

[Tapas Adhikary](https://hashnode.com/@atapas)

[Jul 17, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/66978a2a9ed675a1c10bc2c1#reply-6697ed258777b6c42b6f4433)

Superb [Benjamin Rensch Vinterberg](https://hashnode.com/@JuicyBenjamin)

[RedCode](https://hashnode.com/@RedCodeWds)

[Jul 15, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/66953409f09e14a8b0d180df)

Great! Thanks bro!

[Tapas Adhikary](https://hashnode.com/@atapas)

[Jul 16, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/66953409f09e14a8b0d180df#reply-6695e97fc47fb5061d4e4cff)

thank you [RedCode](https://hashnode.com/@RedCodeWds)

[Sherif Jimoh](https://hashnode.com/@Shefco)

[Jul 12, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/6690f1e25b543a5085efbaa8)

nice piece mate, ty for this. i've always been using map method in scenarios where i prioritizes immutability with some little logic. thanks once again.

[Tapas Adhikary](https://hashnode.com/@atapas)

[Jul 12, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/6690f1e25b543a5085efbaa8#reply-6690fc1cd8a40152818c1718)

My pleasure 🤩

[Ashfiquzzaman Sajal](https://hashnode.com/@ashsajal1)

[Jul 12, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/6690e81f8949c832fb0a6871)

Keep posting about JavaScript. It's useful.

[Tapas Adhikary](https://hashnode.com/@atapas)

[Jul 12, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/6690e81f8949c832fb0a6871#reply-6690ec8946f1acffd05624cd)

Thanks brother [Ashfiquzzaman Sajal](https://hashnode.com/@ashsajal1)

[Tapas Adhikary](https://hashnode.com/@atapas)

[Jul 12, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/6690e3620fcca0de433e8241)

Wow... it got featured!!! So Cool.

[Maggie Joseph](https://hashnode.com/@maggiejoseph)

[Jul 11, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/668fd90689a8c83df1bb8578)

Informative Article.

[Tapas Adhikary](https://hashnode.com/@atapas)

[Jul 12, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/668fd90689a8c83df1bb8578#reply-6690cc7c1bec039241f205ec)

Thanks a lot [Maggie Joseph](https://hashnode.com/@maggiejoseph)

[Klevis Xhyra](https://hashnode.com/@klv)

[Jul 10, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/668eead730abe2a1729020a2)

Great article!! A comment though, when logging out the newArray. Instead of console.log(newNumbers); it should have been console.log(newArray); right?

[Tapas Adhikary](https://hashnode.com/@atapas)

[Jul 11, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/668eead730abe2a1729020a2#reply-668f36ad3204003b79c11f2d)

Yep! Typo, corrected. Thank you 🙏

[Sarfraz Ashrafi](https://hashnode.com/@MohammedSarfraz)

[Jul 24, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/668eead730abe2a1729020a2#reply-66a10d5310b5c2854020c6ad)

literally

[Mohamed Zurfudeen](https://hashnode.com/@zurfudeen)

[Jul 10, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/668e215428e8f2dc0e3a31d2)

good one, though.

[Tapas Adhikary](https://hashnode.com/@atapas)

[Jul 10, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/668e215428e8f2dc0e3a31d2#reply-668e2adc72a3dc93ce558220)

Thank you [Mohamed Zurfudeen](https://hashnode.com/@zurfudeen)

[Favourite Jome](https://hashnode.com/@Favourite)

[Jul 8, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/668bfc85adfae5fe72faacdd)

Wow, this method would be really handy with React. Thanks for sharing, Tapas!

[Tapas Adhikary](https://hashnode.com/@atapas)

[Jul 8, 2024](https://hashnode.com/posts/javascript-array-method-with-immutability/668bd00b1c0dd730ebc759cd/comment/668bfc85adfae5fe72faacdd#reply-668c03f33812e9af72d01879)

You are most welcome [Favourite Jome](https://hashnode.com/@Favourite), and thanks a lot for reading.
