cachaito
9/3/2014 - 8:29 AM

Converting HTMLCollection to Array

var arr = document.getElementsByTagName('div'); //HTMLCollection

Array.prototype.slice.call(arr, 0); //Array

//proces można przeprowadzić sprawniej
var arr = Array.prototype.slice.call(document.getElementsByTagName('div'), 0);

//drugi sposób
var arr = Array.apply(null, document.getElementsByTagName('div'));

// ES6
var arr = [...document.querySelectorAll('button')];
var arr = Array.from(document.getElementsByTagName('button'));