输出javascript对象中属性的名称和值

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了输出javascript对象中属性的名称和值相关的知识,希望对你有一定的参考价值。

The code below will loop through the properties in an object and alert a string. myObject is in JSON notation. The "for ( x in y)" construct does not work if the Prototype.js library is included on the page
  1. // output the name and value of all the objects properties
  2. var s = "";
  3.  
  4. for (var property in myObject)
  5. {
  6. s = s + " "+property +": " + myObject[property] ;
  7. }
  8.  
  9. alert(s);

以上是关于输出javascript对象中属性的名称和值的主要内容,如果未能解决你的问题,请参考以下文章