-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrays.js
39 lines (31 loc) · 1013 Bytes
/
arrays.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
let namesArr = [];
//let namesArr = new Array();
const submitUser = (actionType) => {
let userName = document.getElementById('user-input').value;
editArray(actionType, userName);
//push() agrega un elemento al final de un array y devuelve la longitud
console.log(namesArr);
document.getElementById('user-input').value = '';
printArray();
}
const editArray = (actionType, data) => {
if(actionType === 'push'){
namesArr.push(data);
} else if (actionType === 'unshift') {
namesArr.unshift(data);
//unshift lo pone al principio del Array :o
} else if (actionType === 'pop') {
namesArr.pop();
} else if (actionType === 'shift') {
namesArr.shift();
}
}
const removeUserAtIndex = () => {
let arrIndex = parseInt(document.getElementById('array-index').value);
console.log(typeof arrIndex);
namesArr.splice(arrIndex, 1);
printArray();
}
const printArray = () => {
document.getElementById('names').innerText = namesArr;
}