Q:

Copy single field of all objects in array in single array

I wanted to optimize my code removing a for-loop.
    groupFieldNames = [];
    for (i = 0; i < data.length; i++) {
        groupFieldNames.push(data[i].groupFieldName);
    }

data is an array of objects, each having 4 fields.

I am interested in the one identified as groupFieldName.
Is there a way to avoid the loop and directly push the fields in the array?
EDIT:
I went with @Yosvel Quintero suggestion (to all the guys suggesting the map solution, he was the first one), and checked the performance.
With a data array having ~60k objects I've got:

3ms using map;
11ms using for-loop

Not bad.

A:

You can use Array.prototype.map()
const groupFieldNames = [];
for (i = 0; i < data.length; i++) {
    groupFieldNames.push(data[i].groupFieldName);
}

To:
const groupFieldNames = data.map(o => o.groupFieldName);

