Create Arrays

3 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$39.99
List Price:  $79.99
You save:  $40
€34.51
List Price:  €69.04
You save:  €34.52
£30.03
List Price:  £60.08
You save:  £30.04
CA$56.07
List Price:  CA$112.15
You save:  CA$56.08
A$61.64
List Price:  A$123.30
You save:  A$61.66
S$51.95
List Price:  S$103.92
You save:  S$51.96
HK$310.72
List Price:  HK$621.52
You save:  HK$310.80
CHF 31.86
List Price:  CHF 63.74
You save:  CHF 31.87
NOK kr401.91
List Price:  NOK kr803.93
You save:  NOK kr402.01
DKK kr257.81
List Price:  DKK kr515.68
You save:  DKK kr257.87
NZ$69.66
List Price:  NZ$139.35
You save:  NZ$69.68
د.إ146.86
List Price:  د.إ293.76
You save:  د.إ146.90
৳4,885.14
List Price:  ৳9,771.51
You save:  ৳4,886.36
₹3,508.98
List Price:  ₹7,018.84
You save:  ₹3,509.86
RM169.15
List Price:  RM338.35
You save:  RM169.20
₦58,662.13
List Price:  ₦117,338.93
You save:  ₦58,676.80
₨11,327.80
List Price:  ₨22,658.43
You save:  ₨11,330.63
฿1,315.63
List Price:  ฿2,631.59
You save:  ฿1,315.96
₺1,678.63
List Price:  ₺3,357.69
You save:  ₺1,679.05
B$215.47
List Price:  B$430.99
You save:  B$215.52
R698.96
List Price:  R1,398.11
You save:  R699.14
Лв67.44
List Price:  Лв134.89
You save:  Лв67.45
₩57,256.54
List Price:  ₩114,527.40
You save:  ₩57,270.86
₪131.86
List Price:  ₪263.76
You save:  ₪131.89
₱2,337.73
List Price:  ₱4,676.05
You save:  ₱2,338.31
¥6,071.28
List Price:  ¥12,144.08
You save:  ¥6,072.80
MX$735.85
List Price:  MX$1,471.89
You save:  MX$736.04
QR145.92
List Price:  QR291.87
You save:  QR145.95
P534.01
List Price:  P1,068.15
You save:  P534.14
KSh5,164.70
List Price:  KSh10,330.70
You save:  KSh5,166
E£1,901.52
List Price:  E£3,803.52
You save:  E£1,902
ብር6,038.47
List Price:  ብር12,078.45
You save:  ብር6,039.98
Kz36,470
List Price:  Kz72,949.12
You save:  Kz36,479.12
CLP$37,975.70
List Price:  CLP$75,960.90
You save:  CLP$37,985.20
CN¥284.92
List Price:  CN¥569.92
You save:  CN¥285
RD$2,547.56
List Price:  RD$5,095.76
You save:  RD$2,548.20
DA5,206.89
List Price:  DA10,415.09
You save:  DA5,208.20
FJ$91.93
List Price:  FJ$183.88
You save:  FJ$91.95
Q306.63
List Price:  Q613.34
You save:  Q306.71
GY$8,375.76
List Price:  GY$16,753.62
You save:  GY$8,377.85
ISK kr4,894.77
List Price:  ISK kr9,790.77
You save:  ISK kr4,896
DH368.81
List Price:  DH737.71
You save:  DH368.90
L679.76
List Price:  L1,359.69
You save:  L679.93
ден2,126.49
List Price:  ден4,253.52
You save:  ден2,127.02
MOP$320.46
List Price:  MOP$641
You save:  MOP$320.54
N$693.29
List Price:  N$1,386.76
You save:  N$693.46
C$1,473.12
List Price:  C$2,946.62
You save:  C$1,473.49
रु5,632.10
List Price:  रु11,265.62
You save:  रु5,633.51
S/135.05
List Price:  S/270.14
You save:  S/135.08
K170.84
List Price:  K341.73
You save:  K170.89
SAR149.97
List Price:  SAR299.99
You save:  SAR150.01
ZK905.77
List Price:  ZK1,811.78
You save:  ZK906
L175.43
List Price:  L350.90
You save:  L175.47
Kč839.13
List Price:  Kč1,678.47
You save:  Kč839.34
Ft13,432.80
List Price:  Ft26,868.96
You save:  Ft13,436.16
SEK kr377.49
List Price:  SEK kr755.09
You save:  SEK kr377.59
ARS$58,276.64
List Price:  ARS$116,567.85
You save:  ARS$58,291.21
Bs276.63
List Price:  Bs553.33
You save:  Bs276.69
COP$155,770.71
List Price:  COP$311,580.38
You save:  COP$155,809.66
₡20,093.12
List Price:  ₡40,191.28
You save:  ₡20,098.15
L1,051.86
List Price:  L2,103.99
You save:  L1,052.12
₲283,589.36
List Price:  ₲567,249.64
You save:  ₲283,660.27
$U1,592.21
List Price:  $U3,184.83
You save:  $U1,592.61
zł146.09
List Price:  zł292.22
You save:  zł146.12
Already have an account? Log In

Transcript

Now we are going to talk about arrays. But what is an array? An array is a collection of data. It could be a primitive data type, or reference data type. So for example, we can have an array of foods, foods equals to just add square brackets. And then inside these you add the data that you want to collect inside the inside this array.

So for example, I have apple, orange, and fish. Right? So we have three elements in this array. And as we learned before, everything in JavaScript is an object, right? And arrays are also objects. Therefore, we can create arrays another way using the new keyword.

So how How are we going to do so what we are going to do is just type for var n foods. And instead of using the square bracket mutations, what I'm going to do is I'm going to type equals a new, and then capital A, and then array, and parentheses, and semicolon. So now this is an array. And as you can see, arrays are also objects. By the first version of this array is that it has three elements. The second version is an empty array.

So how are we going to add elements to this array to the secondary, or even the first array? It's so simple, if you already have elements and you want to add elements, adding elements. What you would do is you you use a function called push which is going to add elements to the tail of the Alright, so for example, if I comment this out and use the first array only the first version and the US foods dot push, and I add the element that they want to add to this array or push to this array, for example, it's coffee. Right. And then I use the console, console, that log. And then I just print this array, which is called foods.

And Save and Run, I'm going to get apple, orange fish and coffee because bush will add that element inside the array at the end of this array. And if we use the push on the second version, if I comment this out, and use it on the second version, what I'm going to get is that I'm going to get only coffee because the second version is empty array. So this is how you can add elements to an array if the array is already created.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.