3 ms·
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, y
by z3t4 11y ago
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!
- woah 11y agoSo.... How would a lack of destructuring avoid this? You would still have two undefined variables, plus a bit more typing.
- z3t4 11y agoIt 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);
- tracker1 11y agoI 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!"