I'm getting some data from the API and showing them as a table.
{
name: 'firstName',
cellProps: { numeric: false },
header: 'First',
}, {
name: 'lastName',
cellProps: { numeric: false },
header: 'Last',
}, {
name: 'total',
header: 'Total',
}, {
name: 'country',
cellProps: { numeric: false },
header: 'Country',
},
Then I'm calculating the overall total value using reduce:
const dailytotal = dailySales.reduce((acc, { total }) => acc + total, 0);
now I'm trying to calculate overall total values based on the country to the totals for each country.
const CAfilter = dailySales.filter( { country } => {country} === 'CA');
const CAtotal = CAfilter.reduce((acc, { total }) => acc + total, 0);
I'm getting this error:
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: Unexpected token (49:9)
47 | country;
48 | }
> 49 | === 'CA';
| ^
50 | ;
51 | const CAtotal = CAfilter.reduce((acc, { total }) => acc + total, 0);
在您的过滤器功能中,您没有返回任何内容,您可以这样做
const CAfilter = dailySales.filter( ({ country }) => country.name === 'CA');
const CAfilter = dailySales.filter( ({ country }) => country === 'CA');
You can only omit the parenthesis of an arrow function if it has a single argument. Object destructuring doesn't count as a single argument.
You also had then declared a new object of, essentially:
{country: country}
when all you really wanted was the individual value of country
.
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.