JavaScript #6 – Arrays

This time, we are going to think about store large number of this same type information. For instance, your task is to save information about authors from a library. If you read the previous article, you thought like

but this is very uncomfortable and time-wasting way to set collection of simply information. Much better option is to declare something called array.

Arrays you can also declare like objects (we learn about them in future). So you can use new keywords.

To read the information you should use an index. In JavaScript as in many other programming languages, indexes are zero-based.

JavaScript has provided also many methods to use over array object. By example to loop over an array you can use syntax like this

And result of above example was

Also, you can subtract item from the front and end, as well as push new item.

As you can see, arrays are very naturally manner to save the collection. In many cases, a one-dimensional array is too less to correctly work. Then we need a multi-dimensional array.

 

 

Herbaciarz

 

Leave a Reply

Your email address will not be published. Required fields are marked *