forked from mouredev/hello-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10-array.js
More file actions
56 lines (42 loc) · 1.11 KB
/
10-array.js
File metadata and controls
56 lines (42 loc) · 1.11 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//array
//Declaración de un arreglo
let myArray=[]
let myArray2=new Array()
console.log(myArray)
console.log(myArray2)
myArray=["oliver","rustrian","olirustrian",true]
myArray2=new Array(1,2,3)
console.log(myArray)
console.log(myArray2)
myArray2=new Array(3)
myArray2[0]="oliver"
myArray2[1]="rustrian"
myArray2[2]="olirustrian"
console.log(myArray2)
myArray=[]
myArray[2]="oliver"
myArray[1]="rustrian"
console.log(myArray)
//Metodos Comunes
myArray=[]
myArray.push("oliver") //agrega el ultimo elemento del array
myArray.push("rustrian")
myArray.push("olirustrian")
myArray.push(20)
console.log(myArray)
myArray.pop() //elimina el ultimo elemento del array
console.log(myArray)
myArray.shift() //suprime el primer elemento del array
console.log(myArray)
myArray.unshift("oliver",20)
console.log(myArray)
//length es una propiedad que da el tamaño del arreglo
console.log(myArray.length)
//clear limpia el arreglo
//myArray=[]
myArray=[]
console.log(myArray)
//slice devuelve una copia superficial de una porcion
myArray.push("oliver","rustrian","olirustrian",true)
let newArray=myArray.slice(1,2)
console.log(newArray)