Convert arguments, NodeList, attributes to normal JS array
Little notes for myself
Array.prototype.slice.call(arguments).forEach( el=>console.log(el) ) // arguments to normal JS array
Object.keys({a:0}) // keys to array
[... this.attributes].filter( el=>!el.name.indexOf('data-') ).forEach( el=> console.log(el.name, el.value) ) // DomElement attributes (NamedNodeMap) to array es6
Array.from(this.attributes).filter( el=>!el.name.indexOf('data-') ) // -||- es5 + shim
Array.prototype.forEach.call(document.querySelectorAll( 'input[type=checkbox]' ), item => item.checked = true ); // es5
// ES6
let divsArray = [...document.querySelectorAll('div')]; // Convert NodeList to Array
let argsArray = [...arguments]; // Convert Arguments to Array
For IE and legacy use polyfills from
core-js or
babel-polyfill
No comments:
Post a Comment