0
// I have an object

var obj = {

  customerInfo: {
    firstName: "sdafsd",
    lastName: "sdfsdaf",
  }

}

// I'm provided with a string:

var string = "customerInfo.firstName";

// This obviously won't work for updating the value

obj[string] = "Bob";

The new value of obj

var obj = {

  customerInfo: {
    firstName: "sdafsd",
    lastName: "sdfsdaf",
  },

  "customerInfo.firstName": "Bob"

}

I took a look at Underscore but it appears that it doesn't have anything for updating a value in an object provided the key is a string.

fuzzybabybunny
  • 5,146
  • 6
  • 32
  • 58

0 Answers0