Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
130
rated 0 times [  136] [ 6]  / answers: 1 / hits: 31712  / 11 Years ago, fri, november 1, 2013, 12:00:00

I have the following JSON:



{
meta: {
limit: 20,
next: null,
offset: 0,
previous: null,
total_count: 0
},
objects: []
}


I'm interested in objects: I want to know if objects is empty and show an alert:



something like this:



success: function (data) {
$.each(data.objects, function () {
if data.objects == None alert(0)
else :alert(1)
});

More From » jquery

 Answers
73

Use Array's length property:



// note: you don't even need '== 0'

if (data.objects.length == 0) {
alert(Empty);
}
else {
alert(Not empty);
}

[#74559] Thursday, October 31, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
victorr

Total Points: 193
Total Questions: 86
Total Answers: 105

Location: Pitcairn Islands
Member since Thu, Jun 24, 2021
3 Years ago
victorr questions
Fri, Nov 13, 20, 00:00, 4 Years ago
Sat, Jul 25, 20, 00:00, 4 Years ago
Thu, Jun 11, 20, 00:00, 4 Years ago
;