user1464139
user1464139

Reputation:

How can I check if a variable is neither null or the empty string with javascript?

I have been doing the following:

if (json.RowKeyNew != "") {
    updateGridMeta(entity, json.PartitionKey, json.RowKeyNew, row, tab);
}

However if the json.RowKeyNew is null then the if condition is met which is not what I want. How can I check for something that is not null and not "" ?

Upvotes: 0

Views: 401

Answers (3)

Gyan Chandra Srivastava
Gyan Chandra Srivastava

Reputation: 1380

if (json.RowKeyNew) 

just put varible in if condition it return true if having some value else return false

Upvotes: 0

Asciiom
Asciiom

Reputation: 9975

if (json.RowKeyNew != undefined && json.RowKeyNew != "") {};

Upvotes: 3

Basic
Basic

Reputation: 26756

Try...

if (json.RowKeyNew) {
    updateGridMeta(entity, json.PartitionKey, json.RowKeyNew, row, tab);
}

Upvotes: 0

Related Questions