无涯教程-Javascript - For...in循环语句

这篇具有很好参考价值的文章主要介绍了无涯教程-Javascript - For...in循环语句。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

for ... in 循环用于循环访问对象的属性,由于无涯教程尚未讨论Objects对象,您就会发现此循环非常有用。

“ for...in”循环的语法为:
for (variablename in object) {
   statement or block to execute
}

在每次迭代中,将 object对象中的一个属性分配给 variablename 变量,此循环一直进行到对象的所有属性。

请尝试以下示例来实现" for-in"循环,它将打印网络浏览器的 Navigator 对象。

<html>
   <body>      
      <script type = "text/javascript">
         <!--
            var aProperty;
            document.write("NavigatorObjectProperties<br /> ");        
            for (aProperty in navigator) {
               document.write(aProperty);
               document.write("<br />");
            }
            document.write ("Exiting from the loop!");
         //-->
      </script>      
      <p>Set the variable to different object and then try...</p>
   </body>
</html>

运行上面代码输出

NavigatorObjectProperties 
serviceWorker 
webkitPersistentStorage 
webkitTemporaryStorage 
geolocation 
doNotTrack 
onLine 
languages 
language 
userAgent 
product 
platform 
appVersion 
appName 
appCodeName 
hardwareConcurrency 
maxTouchPoints 
vendorSub 
vendor 
productSub 
cookieEnabled 
mimeTypes 
plugins 
javaEnabled 
getStorageUpdates 
getGamepads 
webkitGetUserMedia 
vibrate 
getBattery 
sendBeacon 
registerProtocolHandler 
unregisterProtocolHandler 
Exiting from the loop!
Set the variable to different object and then try...

参考链接

https://www.learnfk.com/javascript/javascript-forin-loop.html文章来源地址https://www.toymoban.com/news/detail-595755.html

到了这里,关于无涯教程-Javascript - For...in循环语句的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 7 JavaScript循环语句

    7 循环语句 在js中有三种循环语句. 首先是while循环. 它的逻辑和咱们python中的while几乎一模一样, 就是符号上有些许的区别.

    2024年02月12日
    浏览(27)
  • JavaScript 其他循环语句和跳转语句

    一、while语句 While 循环会在指定条件为真时循环执行代码块。 While循环,先进行条件判断,再执行循环体的代码 如果条件不满足,则不会执行循环体,一次都不会 案例: 二、do.....while循环 do/while 循环是 while 循环的变体。该循环会执行一次代码块,在检查条件是否为真之前

    2024年02月06日
    浏览(26)
  • 无涯教程-Lua - for语句函数

    for 循环是一种重复控制结构,可让您有效地编写需要执行特定次数的循环。 Lua编程语言中 for 循环的语法如下- 这是 for 循环中的控制流程- 首先执行 init 步骤,并且仅执行一次。此步骤使您可以声明和初始化任何循环控制变量。 接下来是max/min。这是循环继续执行之前的最大

    2024年02月14日
    浏览(26)
  • 无涯教程-JavaScript - HYPGEOMDIST函数

    HYPGEOMDIST函数替代Excel 2010中的HYPGEOM.DIST函数。 该函数返回超几何分布。 HYPGEOMDIST返回给定样本数量,给定样本数量,总体成功率和总体数量的概率。 将HYPGEOMDIST用于具有有限总体的问题,其中每个观察输出都是成功或失败,并且给定大小的每个子集的选择可能性均等。 Argument 描述

    2024年02月10日
    浏览(34)
  • 无涯教程-JavaScript - IMPOWER函数

    IMPOWER函数以x + yi或x + yj文本格式返回加到幂的复数。求幂的复数的计算方法如下- $$(x + yi)^ n = r ^ ne ^ {n theta} = r ^ n cos n theta + ir ^ n sin n theta $$ 哪里- $$r = sqrt {x ^ 2 + y ^ 2} ::和::theta = tan ^ {-1} left(frac {y} {x} right): :和::theta epsilon(-pi; pi] $$ Argument 描述 Required/Optiona

    2024年02月09日
    浏览(37)
  • 无涯教程-JavaScript - DDB函数

    DDB函数使用双倍余额递减法或您指定的某些其他方法返回指定期间内资产的折旧。 Argument 描述 Required/Optional Cost The initial cost of the asset. Required Salvage 折旧结束时的价值(有时称为资产的残值)。 该值可以为0。 Required Life The number of periods over which the asset is being depreciated (sometime

    2024年02月09日
    浏览(26)
  • 无涯教程-JavaScript - DB函数

    DB函数使用固定余额递减法返回指定期间内资产的折旧。 Argument 描述 Required/Optional Cost The initial cost of the asset. Required Salvage The value at the end of the depreciation (sometimes called the salvage value of the asset). Required Life The number of periods over which the asset is being depreciated (sometimes called the useful

    2024年02月09日
    浏览(31)
  • 无涯教程-JavaScript - CUMIPMT函数

    CUMIPMT函数返回start_period和end_period之间的贷款累计利息。 Argument 描述 Required/Optional Rate The interest rate. Required Nper The total number of payment periods. Required Pv The present value. Required Start_period 计算的第一个期间。 付款期从1开始编号。 Required End_period The last period in the calculation. Required T

    2024年02月09日
    浏览(69)
  • 无涯教程-JavaScript - IMCSCH函数

    IMCSCH函数以x + yi或x + yj文本格式返回复数的双曲余割。 复数的双曲余割定义为双曲正弦的倒数,即 csch(z)= 1 /出生(z) Argument 描述 Required/Optional Inumber A complex number for which you want the hyperbolic cosecant. Required Excel中的复数仅存储为文本。 当将格式为\\\" a + bi\\\"或\\\" a + bj\\\"的文本字符串提供

    2024年02月09日
    浏览(26)
  • 无涯教程-JavaScript - BESSELK函数

    BESSELK函数返回修改后的Bessel函数Kn(x),该函数等效于针对纯虚参判断的Bessel函数。 这些也称为双曲贝塞尔函数。 Argument 描述 Required/Optional X The value at which to evaluate the function. Required N The order of the function. If n is not an integer, it is truncated. Required 如果x为非数字,则BESSELK返回#VALUE!错

    2024年02月09日
    浏览(24)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包