0

I have a grid that I am searching for a specfic row. If the row is not there I want to run a conditional statement. I pull the row like this:

var $row = $table.find("tr[data-id=" + item + "]");

When I use an alert on it, it comes out as what I would expect and 'undefined' when the value is not there. However, when I do a condtional on it I can never get the proper part of the conditional. I have tried:

if(row === 'undefined'){}

if(row == 'undefined'){}

if(row === null){}

if(row == null){}
konkked
  • 3,161
  • 14
  • 19
Emerica.
  • 568
  • 2
  • 9
  • 22

1 Answers1

2

There are two ways you can do this (as it happened, you got really close).

This works

if (typeof row === 'undefined'){}

typeof get the type of the object as a string, so you compare it with the string undefined

so does this

if (row === undefined){}

Note the lack of quotation marks around undefined.

ShuberFu
  • 689
  • 3
  • 15