Cursos /
Introduction to JavaScript
Desafio: Operações com Arrays
Tarefa
- Crie um array chamado
myArray
com os dados fornecidos:["Heine", 25, "Bob", 16]
. - Remova o último elemento,
16
, do array. - Adicione um novo elemento com o valor
21
ao final do array. - Substitua o segundo elemento pelo valor
27
usando indexação. - Imprima o array atualizado no console.
A saída deverá ser:
1. Use the
2. Use the
3. Access the second element in the array using the index
4. To log the array data to the console, use the
pop()
method to remove an element from the end of an
array. 2. Use the
push()
method to add an element to the end of an
array. 3. Access the second element in the array using the index
1
.
4. To log the array data to the console, use the
console.log()
with the array name.
let 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
- Utilize o método
pop()
para remover um elemento do final de um array. - Utilize o método
push()
para adicionar um elemento ao final de um array. - Acesse o segundo elemento do array usando o índice
1
. - Para registrar os dados do array no console, use o
console.log()
com o nome do array.
Tudo estava claro?
Seção 2. Capítulo 8
Conteúdo do Curso
Introduction to JavaScript
Introduction to JavaScript
Desafio: Operações com Arrays
Tarefa
- Crie um array chamado
myArray
com os dados fornecidos:["Heine", 25, "Bob", 16]
. - Remova o último elemento,
16
, do array. - Adicione um novo elemento com o valor
21
ao final do array. - Substitua o segundo elemento pelo valor
27
usando indexação. - Imprima o array atualizado no console.
A saída deverá ser:
1. Use the
2. Use the
3. Access the second element in the array using the index
4. To log the array data to the console, use the
pop()
method to remove an element from the end of an
array. 2. Use the
push()
method to add an element to the end of an
array. 3. Access the second element in the array using the index
1
.
4. To log the array data to the console, use the
console.log()
with the array name.
let 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
- Utilize o método
pop()
para remover um elemento do final de um array. - Utilize o método
push()
para adicionar um elemento ao final de um array. - Acesse o segundo elemento do array usando o índice
1
. - Para registrar os dados do array no console, use o
console.log()
com o nome do array.
Tudo estava claro?
Seção 2. Capítulo 8