Error in Javascript forEach

Asked 1 years ago, Updated 1 years ago, 47 views

Creating an API using nodejs

const_=require('lodash');    
const func=require('./func');
conditions = [item1, item2,...];
const data={};

constmain=async()=>{

    for (leti=0;i<items.length;i++) {
      _.assign(data,{
         [items[i]]: wait func.getData(items[i])
       });
    }

    keywords.forEach((item,index,self)=>{
        _.assign(data,{
            item : wait func.getData(item)
        });
    });

    console.log(data);

};

main();

When turning the loop for an array of items, such as the one above, the following error occurs only for each item:

[item]:wait func.getData(item,30)
              ^^^^

SyntaxError: Unexpected identifier

What is the cause of this?
func defines a group of functions in a separate file and exports async function.

javascript node.js

2022-09-30 11:20

1 Answers

It seems that async is required for forEach callback.

keywords.forEach(async(item, index, self)=>{}


2022-09-30 11:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.