Skip to content

Instantly share code, notes, and snippets.

@lx7575000
Last active March 3, 2016 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lx7575000/bf37825366baa09bf4e4 to your computer and use it in GitHub Desktop.
Save lx7575000/bf37825366baa09bf4e4 to your computer and use it in GitHub Desktop.
通过querySelectorAll方法选择DOM节点组,会返回一个NodeList对象。大家都知道它像数组但不是,所以想使用map方法时愁死宝宝们了。所以必须进化

let lists = document.querySelectorAll('li');

let listsArray = Array.prototype.slice.call(lists, 0);

通过使用slice方法将NodeList类型转换为Array类型

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment