array.length is returning 0 always.... Its returning 0 even some item added into the array...
function validate () {
error = new Array();
if(req.body.category_id==""){
error['category_id'] = "Please select category";
}
if(req.body.text==""){
error['text'] = "Enter the word";
}
if(!(req.body.email!="" && req.body.email.test(/@/))){
error['email'] = "Invalid email id";
}
if((req.session.number1+req.session.number2)!=req.body.captcha){
error['captcha'] = "Captcha verification failed";
}
console.log(error.length);
console.log(error['category_id']);
if(error.length){
return false;
}else{
return true;
}
}
result of the console.log
//0
//Please select category