-
Notifications
You must be signed in to change notification settings - Fork 1
/
16.Array
36 lines (29 loc) · 866 Bytes
/
16.Array
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// -----------------------------------
// An array is an object that can store multiple values at once. For example,
// const words = ["hello", "world", "welcome"];
// ['string', 123, true, []]
// -----------------------------------
// -----------------------------------
// empty array
const myList = [];
// array of numbers
const numberArray = [2, 4, 6, 8];
// array of strings
const stringArray = ["eat", "work", "sleep"];
// array with mixed data types
// const newData = ["work", "exercise", 1, true];
// -----------------------------------
const newData = [
{ task1: "exercise" },
[1, 2, 3],
function hello() {
console.log("hello");
},
];
// -----------------------------------
// ACCESSING ITEMS
const myArray = ["h", "e", "l", "l", "o"];
// first element
console.log(myArray[0]); // "h"
// second element
console.log(myArray[1]); // "e"