Enfield-li – 18-14 Feb 9

Guys, Please help me out, I am not able to get the return value of this code Only got undefined from both values, but why.. let err = { someJunk: "asdfklasdf", detail: "email is bad" }; let fields = ["username", "email"]; const validation = (errDetail, fields) => { fields.forEach((field) => { if (errDetail.includes(field)) { console.log("caught email"); return { errors: { field: field, message: field + "already taken" } }; } return; }); }; const res = validation(err.detail, fields); console.log(res); https://codesandbox.io/s/crimson-framework-yn9i1?file=/src/index.js
crimson-framework-yn9i1 - CodeSandbox
crimson-framework-yn9i1 by 1076462153 using parcel-bundler
Unknown User799d ago
Enfield-Li799d ago
I want to return a single error object when the function caugth a match, so this is not the way I should be doing? So calling return in forEach will not work? I might do a different logic with it.. Just figured out, thanks man!😬
Unknown User798d ago