简体   繁体   中英

How to display the Array length in console with JavaScript/AngularJS

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 [ ]

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]

?

EDIT:

When I'm using:

$log.info(vm.list.length);

it returns 0.

Sure there is

console.log(yourArray.length);

Or if you insist on that format you can do

console.log('Array['+yourArray.length+']');

Take a peek at the docs

I think you're looking for this:

console.log(vm.list.length);

or in your case

$log.info(vm.list.length);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM