Need to use array methods on values returned by document.querySelectorAll? Array.from creates a real array from an array-like object, using its length and indexed properties. section 9.0 section 9.1
Convert function arguments
The arguments object is array-like, but it is not an array. Convert it before calling reduce: const args = Array.from(arguments); const sum = args.reduce((a, b) => a + b); return sum / args.length; section 9.1
Array.from also works with:
- Strings, which become arrays of their indexed characters. section 9.1
- Other objects with a length property; for example, Array.from({ length: 50 }) creates an array of length 50. section 9.1
let nodes = document.querySelectorAll('.accordian-panel');
let nodesArr = Array.from(nodes);
nodesArr.forEach(activatePanel);
Convert the NodeList returned by querySelectorAll, then use forEach to activate each panel. section 9.1
