jonschlinkert / set-value

Set nested properties on an object using dot-notation.
https://github.com/jonschlinkert
MIT License
271 stars 41 forks source link

Setting empty object #14

Closed Misosooup closed 5 years ago

Misosooup commented 5 years ago

Hi, I have been getting issues when trying to use this library.

The overall code works as it should.

However, I have some issues with the following. The code is trying to set the property that I passed in to be an object if it is not an object. The property is an integer at the moment, and it stores the previous value that I have set.

for (let i = 0; i < len; i++) {
  let prop = keys[i];

  if (!isObject(target[prop])) {
    target[prop] = {};
  }

  if (i === len - 1) {
    result(target, prop, value, merge);
    break;
  }

  target = target[prop];
}

With this, the private value that I saved in my class, is going to be NaN instead, before it is being set to the correct value on the next parse.

So if I were to compare the previous value with the new value in my class object, it's going to see it as NaN instead of an integer that was previously set.

doowb commented 5 years ago

@Misosooup can you show some code demonstrating the error that you're seeing? The code snippet above is code from this library.

jonschlinkert commented 5 years ago

closing due to lack of response