What is an Array?
You can also nest arrays (put one array inside another array)
In the above example, one array named
nestedArray is a container for two other arrays
["Cats", 7]. This kind of array is also called a multi-dimensional array.
Accessing Data inside Arrays
Data stored inside the arrays can be accessed using indexes. Just like strings, arrays also have zero-based indexing i.e., the first element of the array has an index on zero, the second element has an index of one, the third element has an index of two, and so on.
To access the data inside an array all you need to do is, write the name of the array along with the index of data you want to access in square brackets (
You can either output this value or store it in another variable for further use.
Accessing Data inside Multi-Dimensional Array
Accessing data inside multi-dimensional arrays can also be done using indexes, but this time we have to use two sets of square brackets. The first one is for the outer-most array (that is the container of all the other arrays) and the second one is for the inside array.
Modifying Data inside Arrays
Manipulating Arrays with push() function
There is a
Manipulating Arrays with pop() function
pop() is invoked or called it pops a value from the end of an array i.e., it removes the last value from the array. But this is not the only thing this function does, when invoked
pop() function also returns the popped-off value and you can store it in another variable.
Manipulating Arrays With shift() function
pop() function, the
shift() function is used to remove the first value from the array. This function also returns the shifted-off value and can be stored in another variable.
Manipulating Arrays With unshift() function
unshift() function is somewhat like the
push() function, the only difference is that it adds the given value to the front of the array instead of the end of the array.
Thank you'll for reading till the end 😌🙌
And don't forget to follow me for more such blogs 😛
Helping fellow newbie developers of the web domain.