Sumit | Javascript + React
Sumit | Javascript + React

@sumitsaurabh927

12 تغريدة 5 قراءة Mar 02, 2023
Javascript explained:
map() method in Arrays
🤔 Are you tired of writing long loops to modify each element of an array?
With Array. map(), you can now do it with just a few lines of code!
📝 Array. map() is a built-in method in JavaScript that creates a new array by performing a function on each element of the original array.
👉 The syntax:
arr. map( callback function { currentValue, index, array ) }
👀 The callback function accepts three arguments - the currentValue, the index of the element, and the array itself.
🤯 One thing to keep in mind is that the original array is not modified by Array. map().
Instead, it creates a new array with the modified elements.
🚀 Here's a simple example to illustrate how it works:
🤔 But what if you want to modify only some elements of the array and leave the others unchanged?
💡 You can use an if-else statement inside the callback function to check for the elements you want to modify.
🚀 Here's an example:
👍 map() is a great tool to use when you want to modify an array without changing the original one.
💡 However, keep in mind that it creates a new array, which can impact performance if you're working with large datasets.
I've also done similar thread on other array methods.
Take a look:
That's a wrap!
Hey, I write two threads every day on web dev and it takes a lot of time and effort.
So, I'd be glad if you could spare me a minute to:
✅ Follow me @sumitsaurabh927 for more of these.
✅ RT the tweet below to show me some love.

جاري تحميل الاقتراحات...