Рет қаралды 2,992
What's with the new with() method on JavaScript arrays?
with() is new in ECMAScript 2023, also known as ES 14, which is the standard for JavaScript.
In this video, we look at how to replace an element in an array. Using the bracket syntax mutates the original array. Using with() instead creates a new array with the changed element, treating the original array as immutable.
with() is a great choice when working in applications that support immutable patterns such as state management libraries and functional programming techniques.
*Links*
JavaScript Code: stackblitz.com/edit/array-with-deborahk
KZbin Video, "Understanding Immutability in JavaScript": kzbin.info/www/bejne/enO9doaGiJJoo7M
KZbin Video, "JavaScript Array sort() vs toSorted() (new in ES 2023)": kzbin.info/www/bejne/gpyqdHd6ZdmLh6s
Includes information on setting up Angular to support ES 2023 features.
*Content*
00:00 Array with() method
00:34 Replacing an Element in an Array
02:08 Array with() method is immutable
03:02 with() supported in ES 2023 and TypeScript 5.2
03:59 The with() method and negative indexes
04:30 Chaining with the with() method
05:03 Wrap Up
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
😊About Me
Hey! I'm Deborah Kurata
I'm a software developer and KZbin content creator. I speak at conferences such as VS Live and ng-conf. I write articles for freeCodeCamp. And I'm a Pluralsight author with courses in the top 10 most popular (out of 7,000+) over the past 5 years. For my work in support of software developers, I've been recognized with the Microsoft Most Valuable Professional (MVP) award, and I'm a Google Developer Expert (GDE).
Contact me on Twitter (X): DeborahKurata
Find my Pluralsight courses: www.pluralsight.com/profile/author/deborah-kurata
Access my freeCodeCamp articles: www.freecodecamp.org/news/author/deborah-kurata/
View my KZbin content: www.youtube.com/@deborah_kurata
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
#javascript #with #withmethod #es14 #es2023