Introduction to Arrays
1) Lets' now talk about our first data structure. And that's gonna be Arrays.
2) An Array is like a big container into which we can throw variables and then later reference them.
3) The two most important data structures, at-least in javascript are arrays and objects.
4) Array Literal syntax:-
5) A different way of creating an Array is by using Array function and new keyword:-
6) Accessing individual Array elements:-
we can access individual array elements by referencing them by index. The first index is 0.
Array.length property will give us the actual length of the Array. It will not respect the indexing rule and will give us the actual number of elements present in the Array.
Since the number of elements in the friends Array is 3, friends.length will also give us the output: 3.
8) Accessing the last element of an Array by Array[Array.length-1] method.
since Array follows the indexing system friends.length = 3 , and friends[friends.length-1] = friends[3-1]
= friends[2]
and in the 2nd index the element is Peter
9) Mutating the Array elements:
Mutating means changing the value of specific Array elements.
In this example we will mutate the value of index 2
10) An Array can hold different data inside it. It can hold strings, numbers , an arithmetic operation, and even an another Array.
So the Jonas Array is holding:-
1) firstName- a variable
2)Schmedtmann- a string
3)2037-1991- arithmetic operation
4) teacher- a string
5) friends - an Array
11) Exercise:

















Comments
Post a Comment