Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Why is my offset NaN? Everything works fine when I comment offset out of the find options. I know there are other questions like this, but none of them solve the problem.
exports.getProducts = (req, res, next) => {
let limit = 10, //10 products per page
offset = 0; //no products skipped
Product.findAndCountAll()
.then((data) => {
let page = req.params.page ? parseInt(req.params.page) : 1,
pages = Math.ceil(data.count / limit);
offset = limit * (page - 1);
console.log(offset) //NaN
console.log(typeof offset) //number
Product.findAll({
limit: limit,
offset: offset,
include: [{
model: Order,
as: 'orders'
model: User,
as: 'user'
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.