Every day Javascript Array method to know Series 1

As a developer in our every day life there are some array method we can't do without.Knowing these array method and how to apply them will help save development time and also enable our code to be clean. so today we will be looking at the first three of those method.

1. join() Method
have you ever thought of converting your array of string into a single string. the join method is a very useful method which enable us achieve that.

Syntax: array.join(separator)

Parameter: accept a parameter called separator as it name implies it help in separating out the element of the array after it has been converted to string.
Enough of the story the best way to learn is by practising, we will be taking a deep dive into how the join method really works

FOR EXAMPE
let arrayOfName = ["james", "john", "kevin"]
and we need to convert arrayOfName into a single string like these "james,john,kevin". to achieve that we call the join method on the array arrayOfName and passing the separator which will be a comma arrayOfName.join(",") and our result will look like these "james,john,kevin".

for more clarity let also convert arrayOfName into something like these james-john-kevin.
To achieve that we call the join method on the array arrayOfName and these time our seperator will be an hyphen arrayOfName.join("-") .
our final result will look like these james-john-kevin.

2. Split()
Split is also a very useful array method that does the opposite of join does. it enables us to split our string into an array of substring.

Syntax: array.split(separator)

the split method also accept a separator parameter which enable it to determine where the spliting should occur

FOR EXAMPLE
let dogName = "i-am-JACK"

and we are ask to convert these string into an array that looks like these ["i","am","JACK"] to achieve that we call the split method on the string dogName and pass the separator parameter which indicate where the splitting is to start from. dogName.split("-") and our finall result will be [ 'i', 'am', 'JACK' ]

3 Sort()
the sort method comes in handy if the order of arrangement of array is very important to us.

syntax: array.sort()

FOR EXAMPLE

let arrayOfLetters = [a,c,d,b,z]
and we are ask to ensure the given array is arrange in an ascending alphabetical order. to achieve that we basically call the sort method on the array arrayOfLetters arrayOfLetters.sort() and javascript will do the work of sorting for us. our final result will look like these [a,b,c,d,z]

stay tuned. more frontend related article on the way. and don't forget to like,comment, share if you find these helpful