49. map() in JavaScript
The map() method is used for creating a new array by applying a provided function to each element in an existing array.
Essentially, it allows you to transform each element in an array and store the results in a new array,
while keeping the original array unchanged.
Example 1:
console.log(squares);
// Output: [1, 4, 9, 16, 25]
Example 2:
const fullNames = people.map(person => `${person.firstName} ${person.lastName}`);
console.log(fullNames);
// Output: ["John Doe", "Jane Smith", "Sam Adams"]