Can't delete an object property?

I have this forEachone 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)
            ) {
                //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 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}

+4
source share

Source: https://habr.com/ru/post/1688006/


All Articles