ajax - Javascript. JSON -
i have sample json
file:
{ "array": [ 1, 2, 3 ], "boolean": true, "null": null, "number": 123, "object": { "a": "b", "c": "d", "e": "f" }, "string": "hello world" }
i need object array
. work want show alert there no "4" in object
tried that:
if(check == null){ alert("not exist") }
but not working. tried put undefined instead of null not working well. should put there ?
rest working fine. know how data json
. issue check function.
$.getjson(host_address ,function(data){ var check = data.array[4] if(check == null){ alert("not exist") } });
you can (i assume have usable json object you've fetched):
var data = { "array": [ 1, 2, 3 ], "boolean": true, "null": null, "number": 123, "object": { "a": "b", "c": "d", "e": "f" }, "string": "hello world" }; // grab array var stuff = data.array; // check see if value in array if(!(4 in stuff)){ alert("not in."); }
Comments
Post a Comment