如何使用JavaScript / AngularJS在控制台中显示数组长度 [英] How to display the Array length in console with JavaScript/AngularJS
本文介绍了如何使用JavaScript / AngularJS在控制台中显示数组长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对在console.log()中显示数组长度有疑问。
I have a question about displaying the Array length in console.log().
这里是一个简单的示例:
Here is a simple example:
vm.list = CrudService.getAllData();
function getAllFonds() {
return ResService.names.query(
succResp,
errResp
);
}
function succResp(resp) {
return resp;
}
function ResService($resource, baseUrl) {
return {
names: $resource(baseUrl + '/api/list/:Id', {
Id: '@Id'
}, {
'update': {
method: 'PUT'
}
}),
....}
}
$log.info(vm.list);
打开控制台时,只会显示:
When I'm opening the console, there will be display only:
Array [ ]
仅当我单击数组时,我会在右侧看到该数组包含47个对象。
Only when I click on "Array" then I see on the right side that the array contains 47 objects.
是否有可能在控制台中显示:
Is there a possibility to display in console:
Array [47]
?
编辑:
当我使用时:
$log.info(vm.list.length);
它返回0。
推荐答案
我想您正在寻找的是
console.log(vm.list.length);
或者在您的情况下
$log.info(vm.list.length);
这篇关于如何使用JavaScript / AngularJS在控制台中显示数组长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文