我想知道如何在 jQuery 中检查数组是否为空或 null。我试过array.length === 0
了,但没有用。它也没有抛出任何错误。
这是代码:
var album_text = new Array();
$("input[name='album_text[]']").each(function(){
if( $(this).val() && $(this).val() != '') {
album_text.push($(this).val());
}
});
if (album_text.length === 0) {
$('#error_message').html("Error");
}
else {
// send data
}