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

JavaScript for of 与 for in 的区别 #1

Open
ClarenceC opened this issue May 10, 2017 · 0 comments
Open

JavaScript for of 与 for in 的区别 #1

ClarenceC opened this issue May 10, 2017 · 0 comments

Comments

@ClarenceC
Copy link
Owner

简单说,for in是遍历键名,for of是遍历键值。例如:
`let arr = ["a","b"];
for (a in arr) {
console.log(a);//1,2
}

for (a of arr) {
console.log(a);//a,b
}`
由于for of的这个特性,他还可以实现对iterator对象的遍历,而for in就是简单的遍历了。

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

1 participant