Enfield-Li
Enfield-Li3y ago

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
1076462153
CodeSandbox
crimson-framework-yn9i1 - CodeSandbox
crimson-framework-yn9i1 by 1076462153 using parcel-bundler
3 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Enfield-Li
Enfield-LiOP3y 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!😬
reactibot
reactibot3y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/941034397296119901

Did you find this page helpful?