0

i got error in if condition columnName=='name'

receivedValues = req.body
var usercolumns = ["name","price","duration","gender"];

    //FOR VALIDATING VALUES BEFORE SUBMISSION
    for(var iter=0;iter<usercolumns.length;iter++)

    {
        columnName = usercolumns[iter];
        console.log("column name",columnName);
        if(receivedValues[columnName] == undefined && (columnName=='name' || columnName=='price' || columnName=='duration' || columnName=='gender'))
        {

enter image description here

5
  • Are you sure 'receivedValues' are not undefined? - where does it come from? Commented Jul 15, 2016 at 8:04
  • Could you add the error text? Commented Jul 15, 2016 at 8:05
  • TypeError: Cannot read property 'name' of undefined at exports.create (D:\New\vabo\nodejs\controller\service.js:42:40) Commented Jul 15, 2016 at 8:23
  • receivedValues = req.body Commented Jul 15, 2016 at 8:28
  • now you can see my question Commented Jul 15, 2016 at 8:46

2 Answers 2

2

Your receivedValues variable seems undefined here, you should add more code to question.

Sign up to request clarification or add additional context in comments.

2 Comments

receivedValues = req.body
do you use body-parser? you should use it to get properties from req.body
0
if(receivedValues && receivedValues[columnName] == undefined && (columnName=='name' || columnName=='price' || columnName=='duration' || columnName=='gender'))

you need to check if receivedValues exist

and you can optimize your code:

if(receivedValues && !columnName in receivedValues && columnName in usercolumns)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.