什么是JavaScript'操作员
我在JavaScript中学习了object.entries
,并且遇到了以下代码段:
const object1 = {
a: 'somestring',
b: 42
};
for (const [key, value] of Object.entries(object1)) {
console.log(`${key}: ${value}`);
}
// expected output:
// "a: somestring"
// "b: 42"
我们可以看到此处使用的““”关键字”;谁能告诉我它是如何工作的?
for (const [key, value] of Object.entries(object1)) {
I was learning about Object.entries
in Javascript and I came across the following code snippet:
const object1 = {
a: 'somestring',
b: 42
};
for (const [key, value] of Object.entries(object1)) {
console.log(`${key}: ${value}`);
}
// expected output:
// "a: somestring"
// "b: 42"
we can see that there is a "of " keyword used in here; can anyone tell me how it works?
for (const [key, value] of Object.entries(object1)) {
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
关键字的
通常用于通过 itoble对象迭代(在您给出的本示例中,是对象的对象。输入)。
有关更多解释和示例,您可以从Mozilla的此文档中找到。
https:https:///develvepender.mozilla。 org/en-us/docs/web/javascript/reference/contements/for ... of
根据Vlaz评论进行编辑:
没有关键字的
也不是独立的。它只是
和等待
语句的的一部分。
The
of
keyword is usually used to iterate through iterable objects (in this example you have given, is the object of Object.entries).For more explanations and examples, you can find out from this documentation by Mozilla.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of
Edited according to VLAZ comment:
There is no
of
keyword nor is it a standalone thing. It's only a part offor..of
andfor await..of
statements.在属性值上进行迭代的循环是ecmascript 2015中的JavaScript规范的功能。
请查看此帖子:
javaScript”关键字(用于循环的...)
The for...of loop, which iterates over property values, is a feature added to the JavaScript specification in ECMAScript 2015.
Please look at this post:
JavaScript `of` Keyword (for...of loops)