Skip to main content

ES6 Array.from function

A useful ES6 function for converting an object into an array.

The Array.from() function in ES6 easily turns most objects recognised as a group of items into a standard array which you can then use other helpful ES6 functions on like map().

<div class="burritos">
    <p>Pulled pork</p>
    <p>Beef</p>
    <p>Chicken</p>
    <p>Vegie</p>
</div>
const burritos = document.querySelectorAll('.burritos > p');
const burritosArray = Array.from( burritos);
const names = burritosArray.map( burrito => burrito.textContent );

console.log(names);