输出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对象中属性的名称和值的主要内容,如果未能解决你的问题,请参考以下文章

选择带有名称[] 和值的复选框(jquery/javascript)

使用 JavaScript 从对象中递归删除属性和值的最快方法是啥?

从核心数据读取时获取属性名称和值

LINQ:获取包含具有特定名称和值的属性的数组中的对象

JavaScript 对象

JavaScript 对象