forked from HackYourFuture/JavaScript1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask02AddDeleteElementsInArrays.js
More file actions
27 lines (27 loc) · 1.03 KB
/
task02AddDeleteElementsInArrays.js
File metadata and controls
27 lines (27 loc) · 1.03 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
let favoriteAnimals = ["blowfish", "capricorn", "giraffe"];
console.log('an array is: '+favoriteAnimals);
function mauroFavoriteAnimal() {
favoriteAnimals.splice([favoriteAnimals.length], 0, 'turtle');
console.log('a new array is: '+favoriteAnimals);
};
mauroFavoriteAnimal();
function jimFavoriteAnimal() {
favoriteAnimals.splice(1, 0, 'meerkat');
console.log('a new array is: '+favoriteAnimals);
};
jimFavoriteAnimal();
console.log("I think this line is very strange. I don't know why am I writing it :(");
console.log('The array has a length of: '+favoriteAnimals.length);
function deleteGiraffe() {
let giraffe = favoriteAnimals.indexOf("giraffe");
favoriteAnimals.splice([giraffe], 1);
console.log('a new array is: '+favoriteAnimals);
};
deleteGiraffe();
function deleteMeerkat() {
let meerkat = favoriteAnimals.indexOf("meerkat");
console.log('The item you are looking for is at index: '+meerkat);
favoriteAnimals.splice([meerkat], 1);
console.log('a new array is: '+favoriteAnimals);
};
deleteMeerkat();