es6 · ES6 Basics
Array.from() is a powerful method which converts array-like objects into real Arrays. Why do you use it in the code below?
let titleElements = document.querySelectorAll('.article .title') let titles = Array.from(titleElements).map( t => t.textContent ); console.log(titles);Answers
- This code is wrong and won't work.
- You use it because it is hip.
- You need it, because querySelectorAll returns a NodeList, which doesn't have the map method, and only arrays do.