Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Articles should already be an associative array in the first place.

I can understand why you think the email example looks better, but whoops, there's a bug, you now got two undefined variables!



I believe in this case articles[0] is pulling a specific article (object) from an array of objects, then destructuring that instance..

   articles.forEach(article => {
     let { title, content, email } = article;
     ...
   })
Might have made that more clear... but .forEach is an ES5 addition...

Given the backlash with ES6, I wonder why we didn't see this with ES5... "OMG they added extra sugar to Array.prototype, we're all gonna die!"


So.... How would a lack of destructuring avoid this? You would still have two undefined variables, plus a bit more typing.


It would probably have looked like this:

  var email = article.email,
    at = email.indexOf("@"),
    ident = email.substr(0, at),
    domain = email.substring(at + 1, email.lengt);




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: