Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
A JavaScript array is a list-like object. You can use arrays to store any kind of data in a sequence, like a list.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
[MUSIC]
0:00
Arrays are one of the most useful data
types you have as a JavaScript developer.
0:04
Arrays are the best way to group
similar data together in a sequence,
0:10
such as a list of customers,
photos, dates, or
0:14
even coordinates indicating
a precise spot on a screen.
0:18
To use arrays effectively,
0:22
you need a way of looking through
them to see the data they hold.
0:23
This action of looking through
arrays is called iteration, and
0:27
JavaScript provides many methods for
iterating over an array.
0:31
For example, you might wanna
transform an array's elements, say,
0:35
from strings to numbers.
0:39
Or you might want to add an array
of numbers and return the sum.
0:41
Maybe you have an array of dates and
0:45
you want to remove all dates before,
say, July 1st.
0:47
In this course,
0:51
I'll show you how to use array methods
to accomplish these kinds of tasks.
0:52
You'll also practice
iterating over arrays so
0:57
you can retain the knowledge
you'll build here.
0:59
Before diving in though, let's take
a moment to review what arrays are.
1:03
An array is a sequenced selection of data,
basically a list of information.
1:08
In fact, arrays are sometimes referred
to as list like objects in JavaScript.
1:13
Think of a list on a piece of paper,
like a shopping list for example.
1:19
A shopping list is a group
of items you need to buy.
1:23
Those items appear in specific order,
starting at the top and going down.
1:27
So when you want to add something to
the list, you write it at the bottom.
1:32
JavaScript arrays have
similar characteristics.
1:37
You can store and position data
inside them as you can with a list.
1:40
To add data to an array, you typically
write it in using a push method for
1:44
example.
1:49
Storing anything whether
it is a name on a list or
1:51
an item in an array is useless
unless you can find it again later.
1:54
To find a list item, you'll typically
start reading at the top and
1:58
go down till you see what you're after.
2:02
You can look through arrays in
a similar manner, but with arrays,
2:05
this process is called iteration.
2:09
And unlike a shopping list,
2:11
which is really a collection of strings,
the names of each item you want to buy,
2:13
you can store any JavaScript data
type as an item in an array.
2:18
A string, a number, an object,
and even another array.
2:22
JavaScript uses integers called
indices to identify the position
2:27
of an item in an array.
2:31
The first item in an array is that index
0, the next item is at 1 and so on.
2:33
This means if you know the location
of an item in an array,
2:40
you can access it directly with its index.
2:43
Put the index and
2:46
square brackets after the array to
access a specific piece of data.
2:47
In the next video, we'll compare
two way to iterate over an array.
2:52
A for loop, and an array method called for
each, I'll see you there.
2:57
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up