re: 10 JavaScript array methods you should know VIEW POST

VIEW PARENT COMMENT VIEW FULL DISCUSSION
 

I'd say it complements them, not replaces (especially map). By example:

const snakeToCamel = str => str.replace(/_([a-z])/g, (match, letter) => letter.toUpperCase());

const camelizeKeys = (obj) =>
  Object.keys(obj)
    .map(k => ({ [snakeToCamel(k)]: obj[k] }))
    .reduce((acc, o) => Object.assign(acc, o), {});

note that using forEach, map, and reduce is much slower than simple for loop. But unless you transform thousands of objects it probably doesn't matter.

Thanks for mentioning performance, though I avoid for loops for stuff like this now after too many times having the loop somehow end up using only the last value in the array for all iterations.

code of conduct - report abuse