什么是JavaScript'操作员

发布于 2025-02-11 01:31:34 字数 438 浏览 1 评论 0原文

我在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

热情消退 2025-02-18 01:31:34

关键字的通常用于通过 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 of for..of and for await..of statements.

谁许谁一生繁华 2025-02-18 01:31:34

在属性值上进行迭代的循环是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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文