repl.it
@MIhm7904/

SampleSet5

Nodejs

Sample Set 5: Arrays

fork
loading
Files
  • index.js
index.js
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
37
38
39
40
41
const listOfNames = ["Kara", "Caesar", "Max", "Joe"]

console.log(listOfNames[0])
//will return Kara
console.log(listOfNames[1])
//will return Caesar
console.log(listOfNames.length)
//will return 4

const someNumbers = [1, 2, 3, 4]

console.log(someNumbers.pop())
//will return 4 (last element in array)
console.log(someNumbers)
//will return [1, 2, 3 ] last number was removed on line 12
console.log(someNumbers.push(5))
console.log(someNumbers)
//will return [1, 2, 3, 5 ]
console.log(someNumbers.push(4))
console.log(someNumbers)
//will return [1, 2, 3, 5, 4 ]
console.log(someNumbers.shift())
console.log(someNumbers)
//will return [2, 3, 5, 4] beginning element was removed on line 22
console.log(someNumbers.unshift(0, 1))
console.log(someNumbers)
//will return [0, 1, 2, 3, 5, 4 ] 0 and 1 were added to beginning on line 25
console.log(someNumbers.includes(3))
//will return true
console.log(someNumbers.join())
//will return 0,1,2,3,5,4
console.log(someNumbers.join(""))
//will return 012354
console.log(someNumbers.join("-"))
//will return 0-1-2-3-5-4
console.log(someNumbers.join(", "))
//will return 0, 1, 2, 3, 5, 4
console.log(someNumbers.reverse())
//will return [4, 5, 3, 2, 1, 0 ]
console.log(someNumbers.sort())
//will return [0, 1, 2, 3, 4, 5 ]