JS ES6 Installation

Currently I’m working on a react project and there I want to use an arrow map function for the iteration purpose. But an error comes as,

Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: D:\Project\src\Components\NameList\NameList.jsx: Unexpected token, expected "," (33:25)

  31 | const printArray = () => {
  32 |     return(
> 33 |         printArray.map() => {
     |                          ^
  34 |             return(
  35 |                 <NameItem 
  36 |                 name = { `${nameList[0].name.first} ${nameList[0].name.last}`}

I think the reason is I haven’t installed ES6 in my local machine. I want to know whether it is possible to install ES6 to an existing project and how to do that…

it’s just that this is not actually proper JS syntax, you can’t put an arrow symbol after invoking the function. Maybe you wanted to put something as as argument of map?

1 Like

You have a couple problems and they have nothing to do needing to install ES6. You do not install ES6. If you are using any recent editor, it already understands ES6.

You have declared printArray as a function but then immediately try to use map on it? The map method is for arrays. Plus, the map method takes a callback function as an argument between the parentheses. You have not provided one. I suggest checking out our Use the map Method to Extract Data from an Array challenge for more information about using the map method.

1 Like

This answer helped me to solve the problem, Thanks for the support.

I’m grateful for the explanation. I went though the challenge and solved the problem.