Hi fellow code newbies! Yes! This is a 2nd part of my recent learnings of JavaScript methods! Mostly for this blog are Array methods! I didn't realize how much more methods I could've used in algorithms until I saw these!
.lastIndexOf()
Returns the index/position of the element that meets the condition. In the example below, it returns the beginning index where the string "name" last occured.
.match()
Returns an array with key-value pairs if function call has a string as an argument and query.
You can also use regular expression to filter out what you need to be matched from a string, and it will return an array of matched elements.
.flat()
If you've heard of flattening the array, this is the method for it. Simple way to explain it, is that it concise a nested array into one. Sets the argument by default of 1.
.some()
A boolean and returns true if any of the element from the array makes the function passed in true. This doesn't manipulate the array and may best work for validations.
.every()
A boolean and will return true if ALL of the elements in the array meets the function passed in as the argument. If the array is empty, it will still return true no matter the condition.
.copyWithin()
IDE themes used for code examples:
- Dracula
- Winter is Coming - Dark Blue
- Sorcerer
- Kabukichō
- Firefly Pro
- Hopscotch Mono
- MDN - Array - for further examples if you need
Top comments (0)