Kieran Geraghty Kieran Geraghty - 6 months ago 30
Javascript Question

Turn assignment into an if statement

Just wanting to know how I could make an if statement from this:

var str = value.flight;
var n = str.includes("RLK");

I have tried

if (n =='true'){
///my function

But it doesn't seem to work. Any help is appreciated, thanks.

Answer Source

n is not a string, but a boolean. You need to check that n is true. You can use the following expression n === true, but it's a bad practice, so simplify if (n) {...

var value = { flight: '123 RLK' };
var str = value.flight;
var n = str.includes('RLK');

if (n) {

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download