Ember JS: Access peekAll length in console

Viewed 62

I am using the following code in my router in the Model hook.

const listings = this.store.peekAll('listings');
console.log(listings); // returns a class with a length of 6
console.log(listings.length); // return 0

I am trying to find a way to access the length in the console. I have read its not available in the console but I'm sure there must be a way.

2 Answers

The peekAll method returns an ArrayProxy from ember-data. You can get access to the contents of that array (and call length/map/etc) on it with .toArray(). So this should work:

const listings = this.store.peekAll('listings');
console.log(listings.toArray().length);

use get property

const listings = this.store.peekAll('listings'); let listings_length = get(listings, 'length');

Related