Skip to content

Instantly share code, notes, and snippets.

@LeeDDHH
Last active January 13, 2020 11:12
Show Gist options
  • Save LeeDDHH/de50105edffe77eeea2ce2ca58927662 to your computer and use it in GitHub Desktop.
Save LeeDDHH/de50105edffe77eeea2ce2ca58927662 to your computer and use it in GitHub Desktop.

HTMLCollectionとNodeListの違い

  • getElementsByTagNameやgetElementsByClassNameの返り値はHTMLCollection
    • DOMに変更を加えた際に取得した値が動的に変更されるのがHTMLCollection
  • querySelectorAllの返り値はNodeList
    • 取得した値が変更されないのがNodeList
  • 違いはHTMLCollectionは動的であり、NodeListは静的である

変数が配列かどうか判定

Object.prototype.toString.call(hoge) => [object Array]

もしくは

hoge instanceof Array => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment