Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce of empty array with no initial value #38

Open
409915016 opened this issue Nov 15, 2020 · 0 comments
Open

Reduce of empty array with no initial value #38

409915016 opened this issue Nov 15, 2020 · 0 comments
Assignees
Labels
bug 确认的问题 enhancement 改进
Milestone

Comments

@409915016
Copy link
Owner

Dashboard.vue?98fa:69 Uncaught (in promise) TypeError: Reduce of empty array with no initial value
    at Array.reduce (<anonymous>)
    at eval (Dashboard.vue?98fa:69)

给定 Reduce 函数第二参数 initialValue 为 0 ,避免相册内没有照片导致的报错

this.numbers.photos = albums
    .map((album) => album.photos.length)
    .reduce((a, b) => a + b, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 确认的问题 enhancement 改进
Projects
None yet
Development

No branches or pull requests

1 participant