I want create a generic method which will access a nested object property and update its value passed as argument.
This is my data structure
var student = {
name: 'Tom',
address: {
pincode: 43301,
street: '12th Main',
city: 'Some city',
},
marks: {
sub1: 111,
sub2: 222
}
}
This is my skeleton of the generic method
updatProperty(student, 'marks.sub1', 125) {
// this method should return student object with marks.sub1 to be 125
}
I have refereed this link , but this will only return me a value