我注意到for...of循环被添加到ECMAScript-6提案中,但直到现在才听说过它们。它们的典型用例是什么?
发布于 2012-11-22 16:11:11
用例是当您想要对数组中的每个元素执行某些操作时。ECMAScript中的for...in会让你遍历数组索引(甚至是不正确的)。
ES6 for...of的Python等价物是for...in,如下所示:
myList = [ "a", "b", 5]
for el in myList:
# el takes on the values "a", "b", 5 in that order
passhttps://stackoverflow.com/questions/13460531
复制相似问题