I have this forEach
one that first checks to see if there is a property and then removes it. Then, if the property is not defined in existingParams
, it adds it again with a new value. It looks like this:
parameters = parameters || {};
let existingParams = this.getUrlParameters();
_.forEach(parameters, function (value, key) {
if ((value !== null || typeof value !== 'undefined')
&& existingParams.hasOwnProperty(key)
) {
console.log("Deleted!: " + existingParams[key])
delete existingParams[key];
return;
} else if (value === null || typeof value === 'undefined') {
return;
}
console.log(existingParams);
if ( ! existingParams.hasOwnProperty(key)) {
Object.defineProperty(existingParams, key, {
value: value,
enumerable: true,
configurable: true
});
return;
}
existingParams[key] = value;
});
The problem is that it never removes the parameter delete existingParams[key];
(first if statement). In the first console.log, I see that the correct parameter is being deleted. But in the second console.log parameter is still there!?!?!?
How is this possible?
existingParams is for example:{minPrice: "1021", maxPrice: "2751", page: 1}
parameters : e.g.{minPrice: 1301, maxPrice: 3081}
source
share