简体   繁体   中英

ReferenceError: "_" is not defined

recipe = new Recipe(_.pick(req.body, ['name', 'tag', 'recipe']));
    await recipe.save();
    

}); 

error:

recipe = new Recipe(_.pick(req.body, ['name', 'tag', 'recipe']));
                    ^

ReferenceError: _ is not defined

you have to import the library before using it like so

// Requiring the lodash library
const _ = require("lodash");

// The source object
var obj = {
    Name: "GeeksforGeeks",
    password: "gfg@1234",
    username: "your_geeks"
}

// Using the _.pick() method
console.log(_.pick(obj, ['password', 'username']));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM