Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Desafio: Operações com Arrays | Variables and Data Types
Introduction to JavaScript

Desafio: Operações com ArraysDesafio: Operações com Arrays

Tarefa

  1. Crie um array chamado myArray com os dados fornecidos: ["Heine", 25, "Bob", 16].
  2. Remova o último elemento, 16, do array.
  3. Adicione um novo elemento com o valor 21 ao final do array.
  4. Substitua o segundo elemento pelo valor 27 usando indexação.
  5. Imprima o array atualizado no console.

A saída deverá ser:

1. 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
      
  1. Utilize o método pop() para remover um elemento do final de um array.
  2. Utilize o método push() para adicionar um elemento ao final de um array.
  3. Acesse o segundo elemento do array usando o índice 1.
  4. 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
course content

Conteúdo do Curso

Introduction to JavaScript

Desafio: Operações com ArraysDesafio: Operações com Arrays

Tarefa

  1. Crie um array chamado myArray com os dados fornecidos: ["Heine", 25, "Bob", 16].
  2. Remova o último elemento, 16, do array.
  3. Adicione um novo elemento com o valor 21 ao final do array.
  4. Substitua o segundo elemento pelo valor 27 usando indexação.
  5. Imprima o array atualizado no console.

A saída deverá ser:

1. 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
      
  1. Utilize o método pop() para remover um elemento do final de um array.
  2. Utilize o método push() para adicionar um elemento ao final de um array.
  3. Acesse o segundo elemento do array usando o índice 1.
  4. 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
some-alt