Challenge: Perform Array Operations
Task
- Create an array named
myArray
with the given data:["Heine", 25, "Bob", 16]
. - Remove the last element,
16
, from the array. - Add a new element with the value
21
to the end of the array. - Replace the second element with the value
27
using indexing. - Print the updated array to the console.
12345let ___ = ["Heine", 25, "Bob", 16]; myArray.___(); myArray.___(21); myArray[___] = 27; console.log(___);
The output should be :
Heine,27,Bob,21
- Use the
pop()
method to remove an element from the end of an array. - Use the
push()
method to add an element to the end of an array. - Access the second element in the array using the index
1
. - To log the array data to the console, use the
console.log()
with the array name.
12345let myArray = ["Heine", 25, "Bob", 16]; // Step 1 myArray.pop(); // Step 2 myArray.push(21); // Step 3 myArray[1] = 27; // Step 4 console.log(myArray); // Step 5
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 2. Capítulo 8
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo
Awesome!
Completion rate improved to 2.33
Challenge: Perform Array Operations
Deslize para mostrar o menu
Task
- Create an array named
myArray
with the given data:["Heine", 25, "Bob", 16]
. - Remove the last element,
16
, from the array. - Add a new element with the value
21
to the end of the array. - Replace the second element with the value
27
using indexing. - Print the updated array to the console.
12345let ___ = ["Heine", 25, "Bob", 16]; myArray.___(); myArray.___(21); myArray[___] = 27; console.log(___);
The output should be :
Heine,27,Bob,21
- Use the
pop()
method to remove an element from the end of an array. - Use the
push()
method to add an element to the end of an array. - Access the second element in the array using the index
1
. - To log the array data to the console, use the
console.log()
with the array name.
12345let myArray = ["Heine", 25, "Bob", 16]; // Step 1 myArray.pop(); // Step 2 myArray.push(21); // Step 3 myArray[1] = 27; // Step 4 console.log(myArray); // Step 5
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 2. Capítulo 8