I am working with an Object array containing product information:
let products = [{ code: 'a', num: 1 }, { code: 'b', num: 2 }];
My goal is to extract the codes from this array: ['a', 'b']
.
Currently, I'm achieving this using lodash:
let codes = [];
_.forEach(products, (product) => {
codes.push(product.code);
});
However, I'm wondering if there's a more efficient way to accomplish this task. Any suggestions?