비어있는 경우 테스트하는 방법 :자바 스크립트 : 어떻게 응답 JSON 배열이
{"array":[],"object":null,"bool":false}
을 그리고 난 다음에 그것을 테스트하고있어, 겉으로는 철저한, if 문 :
$.ajax({
type: "GET",
url: "/ajax/rest/siteService/list",
dataType: "json",
success: function (response) {
var siteArray = response.array;
// Handle the case where the user may not belong to any groups
if (siteArray === null || siteArray=== undefined || siteArray=== '' || siteArray.length === 0) {
window.alert('hi');
}
}
});
하지만 경고가 발생하지 않습니다. : [
'console.log (siteArray) '는 무엇을 표시합니까? – Dennis
[]. siteArray === "[]"시도했지만 그 중 하나가 작동하지 않았다 – Lurk21
빈 배열은 'null', 'undefined' 등과 같지 않습니다. – Phrogz