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.

.mapinstead, but if you're looking for optimal efficient code, not much can beat aforloop...map, orforEach, whatever, it will iterate, just the loop won't be in your code, but you cannot avoid it.