JavaScript ajoute enfin des méthodes immuables pour manipuler les tableaux sans les muter :
toSorted()
toReversed()
toSpliced()
➕ Finies les mutations imprévues
➕ Idéal pour un style fonctionnel
🎥 Démo courte → youtube.com/shorts/tiv8f...
#JavaScript #WebDev #CleanCode #ES2023
#Development #Techniques
Stop using ‘.reverse().find()’ in JavaScript · ‘findLast()’ and ‘findLastIndex()’ are cleaner and safer ilo.im/1672pg by Matt Smith
_____
#Arrays #ES2023 #JavaScript #React #Browser #WebDev #Frontend #Backend
#Development #Introductions
Safe array methods in JavaScript · A tiny syntax change makes a big difference ilo.im/166pp4 by Matt Smith
_____
#Arrays #JavaScript #ES2023 #React #NodeJS #Browser #WebDev #Frontend #Backend
🆕 JavaScript just got cleaner with toSorted()!
No more mutating arrays—sort immutably and write safer code. 💡
📖 Dive into how Array.prototype.toSorted() works and why you should use it:
medium.com/@techwithtwi...
#JavaScript #ES2023 #TechWithTwin
JavaScript example: const arr = [1, 2, 3]; // New in ES2023 const newArr = arr.with(1, 42); console.log(newArr); // [1, 42, 3] // Old way (spread with slice) const oldArr = [...arr.slice(0, 1), 42, ...arr.slice(2)]; console.log(oldArr); // [1, 42, 3]
📢 #JavaScript devs, meet array.with() from #ES2023! 🚀
Replace an array element without mutation.
✅ with() is cleaner and shorter!
Check example 👇
JavaScript example: const users = [ { name: "Simon", age: 25 }, { name: "John", age: 30 }, { name: "Mia", age: 25 } ]; const grouped = Object.groupBy(users, user => user.age); console.log(grouped); /* { 25: [{ name: "Simon", age: 25 }, { name: "Mia", age: 25 }], 30: [{ name: "John", age: 30 }] } */
📌 Object.groupBy()
Since #ES2023 you can use Object.groupBy() to group array elements based on key!
Check example 👇
Very useful! 🚀 #JavaScript
Screenshot of the following snippet: ```ts return rows.rows.map((d) => { d.creators.toSorted((a, b) => { return a.sort_order_in_content -b.sort_order_in_content; }) return d; }); ```
Can you spot the error?
#Javascript #Typescript #ES2023 #ECMAScript
What's with the new with() method on JavaScript arrays?
Use the with() method instead of bracket syntax to modify array elements in an immutable way.
Check out my latest YT video here: youtu.be/Nxe88SVnEOU
#javascript #es2023 #angular