1

I have an object in AngularJS which stores my user data (called $scope.userData). The object looks something like this :

  • user
    • user_profile
  • content
  • sharing_data
    • pages
    • follows
    • subscriptions

with each of those bullet points storing an array of vars. I would like to write a function to update any var stored within, for example I would like to update userData.sharing_data.pages[0], or delete userData.content[2], or add a value such userData.user.user_profile.profile_pic_url = 'myUrl';

How can I find and update any value in a nested object like this, without overwriting the whole object?

Leon
  • 1,851
  • 3
  • 21
  • 44
  • 2
    what have you tried so far? actually doing `userData.user.user_profile.profile_pic_url = 'myUrl'` won't overwrite the whole object – CapitanFindus May 19 '20 at 18:47
  • 3
    See https://stackoverflow.com/questions/18936915/dynamically-set-property-of-nested-object. – Charlie Schliesser May 19 '20 at 19:04
  • 1
    I think this is angular framework related, you might get a better answer if you add this tag as this framework have a different way of watching value changes than plain javascript – zeachco May 19 '20 at 19:46

0 Answers0