I've implemented a JavaScript code snippet that loops through an array of fields to find specific properties and then adds them to a dictionary. For another example, you can check out this site.
return this.getFields()
.reduce((mappings, field) => ({...mappings, [field.id]: field.name}), {});
The functionality works perfectly fine; however, I am encountering an Eslint code style parsing error related to the three dots.
Unexpected token ...
This situation raises three questions:
Is there a way I can modify my code to prevent the parsing error without adding unnecessary length?
Should I consider disabling the ESLint check for this particular error?
What is the technical term for the
...
notation in JavaScript?
As a temporary solution, I could use the following alternative approach. Nonetheless, I would prefer sticking with the original version.
return this.getFields()
.reduce(function(mappings, field) {
mappings[field.id] = field.name;
}, {});