0

This question has been answered earlier. I checked multiple question in SO but i am not able to understand that properly. Apologies for that.

I am using ajax and data is coming from database.

if(data.count > 0 ){
    $.each(data.content, function(key, value ){
if((value.technology) != ''){
 html+='<button class="form-control" disabled>'+value.technology+'</button>&nbsp;';
                            }

i also tried this

if((value.technology6 !== 'null')){
     alert(value.technology6);
  html+='<button class="testsss testss" disabled>'+value.technology6+'</button>&nbsp;';
                            }

and tried this as well

if(!(value.technology7)){
 html+='<button class="testsss testss" disabled>'+value.technology7+'</button>&nbsp;';
  }

problem is i am getting null as output. i am not sure what am i doing wrong and what is the proper way to check null and undefined.

Thanks for your advise.

6
  • Have you tried logging value in your loop? What does data.content look like? Commented Apr 30, 2016 at 15:57
  • if (value.technology) will skip both, but it will also skip false, NaN, 0 and '' so it depends on what you want to do with those Commented Apr 30, 2016 at 15:58
  • are you getting any logs in console? Commented Apr 30, 2016 at 15:58
  • do you want if((value.technology7)){ instead of if(!(value.technology7)){ no "!" Commented Apr 30, 2016 at 16:03
  • Could you post a segment of the data from the server? Commented Apr 30, 2016 at 16:05

2 Answers 2

0

Check Undefined

if(x != undefined)
{
    //x is defined
} else {
    //x is not defined
}

Check Null

if(y != null)
{
    //y is not null, we can do stuff
} else {
    //uh-oh, y is null
}

Also:

z = null;
w = undefined;
console.log(z == w); //Returns true
Sign up to request clarification or add additional context in comments.

Comments

0

please check if value and data are not null or undefined , then write them in alert() function to see what alert you are getting like alert(data.content); or alert(value) ..

else check of null is correct. to check undefined you have to check like

if(data.content != undefined){
// your code here 
}

if you can more elaborate what is in there data and value , might help to solve your problem more appropriately

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.