我有一个对象数组,我想返回每个对象的“message”属性。
我通过调用我自己创建的 oModel.oData 来获取对象。现在我有了这 5 个对象,如何从这 5 个对象中获取“message”属性?
另外,有没有办法计算我总共拥有的对象数量?例如 oModel.oData 对象的总和?
*注意对象位于数组内。
提前谢谢你:)
最佳答案
您可以使用.length来计算数组内的对象数量。
YourArray.lengththis will return the numbers of element (in your case the object) inside the array.
As for the message you will need to loop each object inside of your array. you can easily do that using JQuery library https://jquery.com/
It will look like this
$(function(){
$.each(YourArray,function(i){
console.log(YourArray[i].message);
});
});
或者在 JavaScript 中
for (var i = 0; i < YourArray.length; i++) {
console.log(YourArray[i].details);
};
关于javascript - 我如何访问对象的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36299144/