DEV Community

Cover image for String & Array methods I recently learned - PART 2
Ellaine Tolentino
Ellaine Tolentino

Posted on

String & Array methods I recently learned - PART 2

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!


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.
code application in array & string


Returns an array with key-value pairs if function call has a string as an argument and query.
match code application

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.
Trying out with regex


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.

method in application

Takes in an integer argument as the depth on how much into the array it will flatten.


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.
Some method in application


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.
method in application


This is an interesting one. It takes in 1-3 arguments depending on what you need.
copyWithin(target, start)
copyWithin(target, start, end)
It copies part of the array and returns an array with all the copied parts you need & keeps its length same with the original array.
CopyWithin in 3 examples

Default value of end if left out is array.length

IDE themes used for code examples:

Top comments (0)