Kieran Geraghty Kieran Geraghty - 1 month ago 12
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) {