Extracts the values of a specific key from an array of objects.
This function maps over an array of objects and returns a new array containing the values of the specified key from each object.
The array of objects to pluck values from.
The key whose values are to be extracted.
An array of values for the specified key from each object in the array.
const users = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];const names = pluckArray(users, 'name');console.log(names); // Output: ['Alice', 'Bob'] Copy
const users = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];const names = pluckArray(users, 'name');console.log(names); // Output: ['Alice', 'Bob']
Extracts the values of a specific key from an array of objects.
This function maps over an array of objects and returns a new array containing the values of the specified key from each object.