So I have this array:
[first_name: false, last_name: false, email: false, month: false, day: false, year: false, password: false, password2: false]
Now I if I do this console.log(arrayName.length) it will return 0; why? What I’m doing wrong?
//LE
This is how I do it:
var errors = {};
$('.register-front').delegate('button','click',function(){
var $this = $(this).parent().parent().parent();
$this.find('input,select').each(function(){
if(!$(this).val() || ($(this).val() == '-1'))
{
errors[$(this).attr('name')] = false;
}
});
console.log(errors.length);
return false;
});
I made some changes but I still don’t get it….
Your notation seems odd. The square brackets are for an array, but the contents are object attribute/value notation. I don’t think that will work. You can turn your expression into an object by replacing the
[]with{}, but then, objects don’t have length. You can get the number of keys in an object with:Alternatively, you can iterate through the object keys with:
EDIT For the specific code you added, you can replace this line:
with: