[英]Objects as Associative Arrays: for loop
Is it possible to loop through a data set of objects as associative arrays?是否可以将对象数据集作为关联 arrays 循环?
I have a bunch of JSON data, and would like to loop through all of the data sets and pull out a property in each object.我有一堆 JSON 数据,并想遍历所有数据集并在每个 object 中提取一个属性。
for example:例如:
for ( var i = 0; i <= 20; i++){
var oblivion = i;
var myObject = new MYobject( oblivion);
oblivionLoader(myObject);
}
function oblivionLoader(myObject)
{
for ( i = 1; i<=2; i++)
{
var changer = myObject.oblivion[i];
var infoText = GetDetailsText(changer);
infoText.html(myObject.toString());
}
}
If this is possible please show me how.如果这是可能的,请告诉我如何。 Otherwise I am concluding it is impossible...
否则我的结论是不可能的...
you can use a for in
loop to loop through properties of an object.您可以使用
for in
循环遍历 object 的属性。
var myObject = { prop1:"1", prop2:"2", prop3:"3" },
property;
for ( property in myObject ) {
if ( myObject.hasOwnProperty( property ) {
alert( myObject[property] );
}
}
the bracket and dot syntax is interchangeable in JavaScript.括号和点语法在 JavaScript 中可以互换。
That being said, I have no idea what you're trying to do in you're example...话虽这么说,我不知道你想在你的例子中做什么......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.