I have that following function which updates a single property inside the localStorge
/**
* Update a single property
* @param key
* @param value
* @return Bool
*/
SelectedCampaign.updateProperty = function (key, value) {
var savedCampaign = localStorageService.get(selecteCampaignKey);
savedCampaign[key] = value;
success = localStorageService.set(selecteCampaignKey, savedCampaign);
return success;
};
So if i'm sending for example
updateProperty('name','The name')
, it will update the name key of the object.
I want to improve this function so it will be able to update a multidimensional key - For example
updateProperty('location.city.zone','The zone')
I'm having a hard time to create a function which does it. It probably needs some recursive function do it. Also, it needs to validate that the key is valid (not undefined/null) but an object Any idea?