0

I am unable to use the JS reduce function to transform the following object:

obj = {
   "key1":"value1",
   "key2":"value2"
}

to this:

newObj = {
  "key1":{
     "S":"value1"
  },
  "key2":{
     "S":"value2"
  }
}

I am using the JavaScript reducer function for this transformation like this:

let newObj = Object.entries(obj)
    .reduce((result, entry) => {
        return {
            ...result,
            entry[0]: entry[1]
        }
    }, {})

But I get the following error:

            entry[0]: entry[1]
                                ^

SyntaxError: Unexpected token '['

How can I resolve this to transform the object?

Web User
  • 6,996
  • 13
  • 57
  • 86

0 Answers0