LoginSignup
3

More than 3 years have passed since last update.

posted at

updated at

Organization

querySelectorAllをmapする

スクレイピング時に手軽にリストを展開したいとき

querySelectorAllArrayではないのでforEachはありますがmapはありません
中のコンテンツを取り出したいときにforEach+pushだと煩わしさがあるのでmapでなんとかしたいと思うでしょう。

以下の方法でmapすることができます

サンプルコード

const data = [...document.querySelectorAll('.list li')].map((node) => {
  return node.textContent
})

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
3