mapConfig(config: IConfigItem[], dataModel: IDataModel): IConfigItem[] {
return config.map(c => {
const entries: [string, string][] = Object.entries(c);
entries.forEach(e => {
const configValue = e[0];
const configKey = e[1];
if (configKey in dataModel) {
c[configValue] = dataModel[configKey];
}
});
return { ...c };
});
}
Within my service class, there is a function called `mapConfig` which I am invoking from an Angular component.
const configCopy = [...this.config];
const dataModelCopy = { ...this.dataModel };
const mappedConfig: IConfigItem[] = this.loader.mapConfig(
configCopy,
dataModelCopy
);
To prevent the base object `this.config` from being modified, I created a copy of it and passed it to the `mapConfig` function. However, despite this precaution, the base object `this.config` still gets updated. I'm uncertain about what I might be doing wrong.