Junior — Middle
Mis on Map meetodi peamine ülesanne ja kuidas seda rakendatakse andmekogumitega töötamisel?
sobes.tech AI
Vastus AI-lt
The map method is used to transform each element of a collection (e.g., an array) into a new element, forming a new array of the same length. The main task is to apply a function to each element of the original array and obtain an array of results.
Example in JavaScript:
const numbers = [1, 2, 3, 4];
const squares = numbers.map(x => x * x);
console.log(squares); // [1, 4, 9, 16]
This is useful when working with data, where you need to transform or extract certain values from a collection without modifying the original.