Individual Elements and Length
Individual Elements
If we wanted to know exactly who the second employee in our list was we could run this code:
Your console should have displayed Amanda Huggenkiss
. Remember we use emp[1]
because arrays are zero-indexed.
Length
There's also a way to find out the length of our array:
Our output is 3
. This is obviously because there are three elements in our array. You can also think of it as 3 is one more than the index of our final element. You could also write something like this:
Which would output as [ 'Joe King', 'Amanda Huggenkiss' ]
. This is because we set emp.length
equal to 2, meaning we only wanted the first two elements in the array.
Last updated