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

bookArray Methods (map)

Veeg om het menu te tonen

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?

Selecteer het correcte antwoord

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 7

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

Sectie 1. Hoofdstuk 7
some-alt