JavaScriptでtoArrayができる!Array.fromは超便利

投稿日: 2017/09/12  更新日: 2018/06/05

JavaScript 



document.getElementsByClassName('hiyoko').forEach(a => {
    console.log(a);
})

これはできない。

VM501:1 Uncaught TypeError: document.getElementsByClassName(...).forEach is not a function

Array.from(document.getElementsByClassName('hiyoko')).forEach(a => {
    console.log(a);
})

これならできる!



このエントリーをはてなブックマークに追加     

profile
profile

洋ちゃん

@c5apple

システムエンジニアをしています。二児の父です。

夢は天井から床までビッシリ並んだ本棚のある書斎を作ること!