I've got this forEach
that first checks if a property is there and then deletes it. Then if the property is not defined in existingParams
it appends it again with the 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)
) {
//First console.log
console.log("Deleted!: " + existingParams[key])
delete existingParams[key];
return;
} else if (value === null || typeof value === 'undefined') {
return;
}
//Second console.log
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 delete's a param delete existingParams[key];
(first if statement). In the first console.log I see that the correct param is being deleted. But in the second console.log the param is still there!?!?!?
How is this possible?
existingParams is for example: {minPrice: "1021", maxPrice: "2751", page: 1}
parameters is for example: {minPrice: 1301, maxPrice: 3081}