what is good practice to run custom functions on a specific value of an array of objects in javascript?

You can use map method and some parameter destructuring.

const arrayOfObjects = [{"v1":"foo","v2":"bar","v3":"foobar"},{"v1":"foo2","v2":"bar2","v3":"foobar2"}]
const f1 = (v) => v.toUpperCase();
const f2 = (v) => v.toLowerCase();

const result = arrayOfObjects
  .map(({ v1, v2, ...rest }) => ({
    ...rest,
    v1: f1(v1),
    v2: f2(v2)
  }))
  
console.log(result)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top