Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why delete obj[0] #2773

Closed
hooper-hc opened this issue Jul 14, 2018 · 2 comments
Closed

why delete obj[0] #2773

hooper-hc opened this issue Jul 14, 2018 · 2 comments

Comments

@hooper-hc
Copy link

hooper-hc commented Jul 14, 2018

in unjs 1.9.1 source

  _.each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
    var method = ArrayProto[name];
    _.prototype[name] = function() {
      var obj = this._wrapped;
      method.apply(obj, arguments);
      // TODO why ? 
      if ((name === 'shift' || name === 'splice') && obj.length === 0) delete obj[0];
      return chainResult(this, obj);
    };
  });

this line why need 'delete obj[0];'
if ((name === 'shift' || name === 'splice') && obj.length === 0) delete obj[0];

@simulency
Copy link

https://stackoverflow.com/questions/24725560/javascript-why-need-to-delete-the-0-index-of-an-array

@hooper-hc
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants