Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我注意到for...of循环被添加到 ECMAScript-6 提案中,但直到现在才听说过它们。他们的典型用例是什么?
用例是当您想对数组的每个元素执行某些操作时。 for...in在 ECMAScript 中会有点让你检查数组索引(甚至是不正确的)。
for...in
ES6 的 Python 等价物for...of是for...in,如下所示:
for...of
myList = [ "a", "b", 5] for el in myList: # el takes on the values "a", "b", 5 in that order pass