Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array.from() 的問題 #8

Open
jawayang opened this issue Jun 29, 2016 · 2 comments
Open

Array.from() 的問題 #8

jawayang opened this issue Jun 29, 2016 · 2 comments

Comments

@jawayang
Copy link
Contributor

想問一下昨天導讀的內容
裡面有個範例

let ps = document.querySelectorAll('p');
Array.from(ps).forEach(function (p) {
  console.log(p);
});

Array.from 是用來把物件轉成陣列對吧?
document.querySelectorAll 回來的結果不是 陣列嗎?
還是他是類陣列?
還是其實陣列也是類陣列的一種?
為何這邊還需要用 Array.from() 去包 ps?
求解~

@neighborhood999
Copy link
Contributor

neighborhood999 commented Jun 29, 2016

Array.from 可以 each array like 的陣列或是 iterable objectsquerySelectorAll 它所回傳的是一個 array like。

@jawayang
Copy link
Contributor Author

原來如此~ NodeList not an Array
https://developer.mozilla.org/zh-TW/docs/Web/API/NodeList

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants