0

I get an unexpected error while following some code examples which I found online. I assume I have made some mistake, but comparing to other examples here, I cannot find the mistake. I am trying to include an if function within a map function:

const compProfileRemoveHandler = compProfileId => {
    todoList.map(profile =>(
     if (profile.id !== compProfileId) {some code}
))};

Does anyone know why I get the following error: "Parsing error: Unexpected token" (and the 'if' is marked under the statement).

Many thanks for your help!

2
  • 5
    you need to use curly braces instead of round brackets for your function body .map(profile => { if ..}) - also you must always return something from your map method or you'll get undefined as your element Commented May 1, 2019 at 10:15
  • 2
    @NickParsons also remember that if you're returning an object, it's the implicit return feature, but you need to wrap the object in parentheses to avoid it being parsed as the body. Commented May 1, 2019 at 10:20

1 Answer 1

7

try this:

const compProfileRemoveHandler = compProfileId => {
    todoList.map(profile => {
     if (profile.id !== compProfileId) {some code}
} )};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.