Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Manipulating Arrays | Advanced Primitives and Reference Types
Quizzes & Challenges
Quizzes
Challenges
/
JavaScript Data Types Foundations

bookManipulating Arrays

12345678910111213141516171819
// Adding items to an array const fruits = ["apple", "banana"]; fruits.push("orange"); // Adds "orange" to the end fruits.unshift("strawberry"); // Adds "strawberry" to the beginning // Removing items from an array const lastFruit = fruits.pop(); // Removes the last item ("orange") const firstFruit = fruits.shift(); // Removes the first item ("strawberry") // Iterating over array elements fruits.forEach(function(fruit, index) { console.log(index + ": " + fruit); }); // Creating a new array with map const upperFruits = fruits.map(function(fruit) { return fruit.toUpperCase(); }); console.log(upperFruits); // ["APPLE", "BANANA"]
copy

Arrays in JavaScript are flexible, allowing you to add, remove, and transform elements efficiently. The push method adds one or more elements to the end of an array, while pop removes the last element and returns it. If you want to add or remove elements at the beginning, use unshift and shift respectively. These methods make it easy to manage lists of data, such as keeping track of items in a shopping cart.

To process or examine each item in an array, use the forEach method. This runs a function for every element, giving you access to both the value and its index. When you need to create a new array based on the original, such as converting all strings to uppercase, use the map method. map applies a function to each element and returns a new array with the results, without changing the original array.

These array methods help you build dynamic, interactive experiences by letting you easily update, display, and transform lists of data.

question mark

Which array method creates a new array by applying a function to each element in the original array?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 4

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

Suggested prompts:

Can you explain the difference between `forEach` and `map` in more detail?

What other useful array methods are there in JavaScript?

Can you show how to filter items in an array?

Awesome!

Completion rate improved to 6.25

bookManipulating Arrays

Deslize para mostrar o menu

12345678910111213141516171819
// Adding items to an array const fruits = ["apple", "banana"]; fruits.push("orange"); // Adds "orange" to the end fruits.unshift("strawberry"); // Adds "strawberry" to the beginning // Removing items from an array const lastFruit = fruits.pop(); // Removes the last item ("orange") const firstFruit = fruits.shift(); // Removes the first item ("strawberry") // Iterating over array elements fruits.forEach(function(fruit, index) { console.log(index + ": " + fruit); }); // Creating a new array with map const upperFruits = fruits.map(function(fruit) { return fruit.toUpperCase(); }); console.log(upperFruits); // ["APPLE", "BANANA"]
copy

Arrays in JavaScript are flexible, allowing you to add, remove, and transform elements efficiently. The push method adds one or more elements to the end of an array, while pop removes the last element and returns it. If you want to add or remove elements at the beginning, use unshift and shift respectively. These methods make it easy to manage lists of data, such as keeping track of items in a shopping cart.

To process or examine each item in an array, use the forEach method. This runs a function for every element, giving you access to both the value and its index. When you need to create a new array based on the original, such as converting all strings to uppercase, use the map method. map applies a function to each element and returns a new array with the results, without changing the original array.

These array methods help you build dynamic, interactive experiences by letting you easily update, display, and transform lists of data.

question mark

Which array method creates a new array by applying a function to each element in the original array?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 4
some-alt