Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Array Methods (map) | Section
JavaScript Essentials for React Native Development

bookArray Methods (map)

Deslize para mostrar o menu

The map method is a powerful tool for transforming arrays in JavaScript. It allows you to create a new array by applying a function to each element of an existing array. The original array remains unchanged, making map a non-mutating method.

12345
const numbers = [1, 2, 3, 4]; const doubled = numbers.map(function(number) { return number * 2; }); console.log(doubled); // Output: [2, 4, 6, 8]
copy

When you call array.map(callback), the callback function is executed once for every element in the array. The callback receives up to three arguments:

  • The current element value;
  • The current element's index;
  • The original array.

Most commonly, you will use only the first parameter—the current value. The function you provide should return a value, which will become the corresponding element in the new array.

This makes map ideal for tasks like:

  • Converting numbers to strings;
  • Modifying each object in an array of objects;
  • Extracting a specific property from each object in an array.

Since map always returns a new array, you can chain it with other array methods or use it to keep your data transformations clear and predictable.

question mark

What does the map method return?

Selecione a resposta correta

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 7

Pergunte à IA

expand

Pergunte à IA

ChatGPT

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

Seção 1. Capítulo 7
some-alt