const numbers = [1, 2, 3, 4, 5]; const doubledNumbers = _.map(numbers, num => num * 2); console.log(doubledNumbers); // [2, 4, 6, 8, 10]
const users = [ { id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }, { id: 3, name: 'Charlie' }, ]; const userIds = _.map(users, user => user.id); console.log(userIds); // [1, 2, 3]In this example, `_.map()` takes the `users` array and a callback function that extracts the `id` property from each object. This creates a new `userIds` array with only the user IDs. The `_.map()` function is part of the Underscore library.