Note: Array index will start from zero. It means the position of the first element in the array will be 0, and then 1 and the numbering will continue till last element.
We can create array object by two ways, or rather three ways. Don’t worry, we will check it out, to understand its ease of use.
At 0 you will get SEO, at 1 you will get web hosting and so on. We have just created an array that will have the elements, like SEO, Web hosting and etc.
We have used the same example, but using the constructor here. We have just mentioned the values here. In case you just want to mention the array length and not the value, then can go for a third way.
var sharplesson = new Array (6)
Now this will insure that the total number of elements that will go inside is 6 only. Now you will assign data to each of the elements in the array.
sharplesson  = “SEO”;
sharplesson  = “Web Hosting”;
sharplesson  = “Html”;
sharplesson  = “CSS”;
sharplesson  = “Blogging”;
- Constructor () – We already used in the above example. It will return the function which made the object.
- length () – It will let you know the number of elements in an array.
- prototype() – If you want to add methods or any properties to the array object, then you can use it.
- isArray() – You can use this method to check for an array, if it is, then it will return true and if not, then it will return false.
- concat () – It means joining, you can use it, if you want to join two arrays. It will join it and then return the final result.
- join () – If you want to join the elements of the array itself, then you can use ‘join’ method.
- reverse () – It will reverse the order of the normal result. The first element will go to last and last will come in first place.
- slice () – If you want to show only selected elements of the array, then you can use slice () there.
- toString () – If you want results in a string, then you can convert an array into a string using this method. ( The funny part is you can test join () as well, most of the time it will give the same result).
- sort () – It will sort the result in ascending, descending, numeric or alphabetic order.
- splice () – If in case you forgot to add something to add to array, then you can use the splice method to do so. Same will apply for the removal of the element as well.
- pop () – It will help you do delete the last element of the array and will show the rest of the results.
- push () – It will work opposite to pop method. It will add elements at the last of the array and will show the updated result.
The output will be: