javascript - 如果在 map 函数: Getting unexpected error内

标签 javascript arrays reactjs function if-statement

在遵循我在网上找到的一些代码示例时,我遇到了意外错误。我认为我犯了一些错误,但是与这里的其他示例相比,我找不到错误。我试图在 map 函数中包含 if 函数:

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

有谁知道为什么我收到以下错误:“解析错误:意外的 token ”(并且“if”标记在语句下)。

非常感谢您的帮助!

最佳答案

试试这个:

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

关于javascript - 如果在 map 函数: Getting unexpected error内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55934672/

相关文章:

javascript - SignalR 从服务器返回字符串到客户端

javascript - 粗箭头中的词法 this 上下文

php - 如何将一串数字转换成数组?

reactjs - 如何使用MaterialUI Button调用功能组件中按钮的组件onClick

css - 谷歌按钮不呈现 - react.js

javascript - 如何在 InDesign 中获取选定文本后的第一个字符?

javascript - 如何动态循环 json 字符串中的所有值

python - 使用 python/numpy 评估数组上的多变量函数

javascript 如何创建对象数组

css - 如何使用 React-Bootstrap 映射()行中的元素