Leaning Thread: About slice method in JavaScript:
The slice() method is a built-in JavaScript function that returns a shallow copy of a portion of an array into a new array object.
#4
The end parameter is the zero-based index at which to end extraction. slice() extracts up to but not including end. If negative, it counts back from the end of the array.
Use Cases:
When you have a use case where more than 1 element is expected to be returned then you can use the filter() method. But if you expect only a single element to be returned from the array, then you can use find() and avoid extra iterations.
🧵 Let’s talk about two powerful array methods in JavaScript: array.find() and array.filter(). They’re both used to search through an array, but they have different use cases and return different results. Let’s dive in! 👇
In filter(), the whole array is iterated despite the fact that the element being searched for is present at the beginning. But in find(), as soon as the element that satisfies the condition is found, it gets returned.
Learning thread:
#1
Just learned about useSearchParams in react-router-dom today! It’s a hook used to read and modify the query string in the URL for the current location.
#React#JavaScript#WebDevelopment
#5
You can use various methods provided by the URLSearchParams class to work with this data, such as get(), getAll(), has(), set(), delete(), and more.
#3
Just like React’s useState hook, setSearchParams also supports functional updates. This means you can provide a function that takes the current state and returns an updated version. #React#JavaScript#WebDevelopment
#2
searchParams is an object that contains the current location’s search parameters, and setSearchParams is a function that can be used to update them. #React#JavaScript#WebDevelopment