JavaScript:获取对象属性的值

JavaScript:获取对象属性的值,javascript,javascript-objects,Javascript,Javascript Objects,我试图获取对象所有属性的值,并尝试使用object.values() var a=queryPlan.combo.getFilterMapOfIdToWgt(); console.log(Object.values(a)) 但它实际上包含了很多价值: [constructor] 0:constructor activeErrorsTpl:(8) ["<tpl if="errors && errors.length">", "<ul class="{listCls

我试图获取对象所有属性的值,并尝试使用
object.values()

var a=queryPlan.combo.getFilterMapOfIdToWgt(); console.log(Object.values(a))

但它实际上包含了很多价值:

[constructor]
0:constructor
activeErrorsTpl:(8) ["<tpl if="errors && errors.length">", "<ul class="{listCls}">", "<tpl if="Ext.enableAria">", "<tpl if="fieldLabel"><div>{fieldLabel}</div></tpl>", "</tpl>", "<tpl for="errors"><li>{.}</li></tpl>", "</ul>", "</tpl>"]
activeUI:"default"
autoGenId:true
auxStore:constructor {removed: Array(0), blockLoadCounter: 0, isInitializing: false, initConfig: ƒ, initialConfig: {…}, …}
bindings:[]
bodyEl:constructor {dom: div#hemonth-1050-bodyEl.x-form-item-body.x-form-item-body-default.x-form-text-field-body.x-form-text…, id: "hemonth-1050-bodyEl", el: constructor, initConfig: ƒ, initialConfig: {…}, …}
[构造函数]
0:构造函数
activeErrorsTpl:(8)[“”,“
    ”,“”,“{fieldLabel},”,“
  • {.}
  • ”,“
”,“”] activeUI:“默认值” 奥托genid:对 auxStore:constructor{removed:Array(0),blockLoadCounter:0,isInitializing:false,initConfig:ƒ,initialConfig:{…},…} 绑定:[] bodyEl:constructor{dom:div#hemonth-1050-bodyEl.x-form-item-body.x-form-item-body-default.x-form-text-field-body.x-form-text…,id:“hemonth-1050-bodyEl”,el:constructor,initConfig:ƒ,initialConfig:{…},}
我正在尝试访问每个值。有可能得到它吗?如果有,我如何得到它? 非常感谢您的帮助和提前感谢。

ES6+

如果使用ES6+,则可以使用
for..of
循环:

var myArray = [ 1, 2, 3 ];

for (var v of myArray) {
   console.log( v );
}
// 1
// 2
// 3
var myArray = [1, 2, 3];

for (var i = 0; i < myArray.length; i++) {
    console.log( myArray[i] );
}
// 1 2 3
for..of
循环直接迭代对象属性的值

ES6之前的课程

对于ES6之前的版本,您可以使用标准的
For
循环:

var myArray = [ 1, 2, 3 ];

for (var v of myArray) {
   console.log( v );
}
// 1
// 2
// 3
var myArray = [1, 2, 3];

for (var i = 0; i < myArray.length; i++) {
    console.log( myArray[i] );
}
// 1 2 3
var myArray=[1,2,3];
对于(var i=0;i
让obj={
键1:‘val1’,
打印:(x)=>{console.log(x)}
}
for(obj中的var attr){
if(对象类型[attr]=“函数”){
obj[attr]('123');
}
如果(对象的类型[attr]=“字符串”){
log('hi attr is:',attr',with value:',obj[attr])
}

}
sample input please有人应该如何帮助您回答这个问题。
for。。of
用于阵列。对于对象,请使用
For。。在
中,您是对的,但是
for..of也适用于具有自定义迭代器的对象。