+ 1

Label text in JavaScript

Okay one question is say you have an array like var this=[“burger”,”cucumber”] And you want to make and if statement that says if( this text is on the word burger) then how you do that

24th Sep 2020, 2:50 PM
Imhoopin2 Aball
Imhoopin2 Aball - avatar
12 Respuestas
+ 2
var a=["burger","cucmber"] for(i of a){ if(i=="burger" && i.search("u")){ console.log("u is in burger") } }
24th Sep 2020, 3:04 PM
Abhay
Abhay - avatar
+ 1
Yes. Array of your 2nd post.
24th Sep 2020, 5:28 PM
Jayakrishna 🇮🇳
0
so do i need both in the if statement or can i just put the i==“burger”
24th Sep 2020, 3:21 PM
Imhoopin2 Aball
Imhoopin2 Aball - avatar
0
You can do it however you like
24th Sep 2020, 3:24 PM
Abhay
Abhay - avatar
0
okay its saying that for(i of a) is not a thing so do i put for(var i=0;i<5;i++) or something like that
24th Sep 2020, 3:25 PM
Imhoopin2 Aball
Imhoopin2 Aball - avatar
0
for( let i of a) if( i == "burger") console.log(i); Is this you are looking...?Imhoopin2 Aball
24th Sep 2020, 3:33 PM
Jayakrishna 🇮🇳
0
its telling me that a is not defined
24th Sep 2020, 3:56 PM
Imhoopin2 Aball
Imhoopin2 Aball - avatar
0
yes you can even do for(var i=0;i<2;i++){ if (a[i]=="burger"){ for(j=0;j<a[i].length;j++){ if (a[i][j]=="u"){ console.log('u in burger') } } } for(i of a )is actually a thing ,it iterates over every element in list and assign value to i
24th Sep 2020, 3:57 PM
Abhay
Abhay - avatar
0
is a the array?
24th Sep 2020, 3:58 PM
Imhoopin2 Aball
Imhoopin2 Aball - avatar
0
Obviously I have used "a" like you used "this" ,
24th Sep 2020, 3:59 PM
Abhay
Abhay - avatar
0
oh okay😁
24th Sep 2020, 4:01 PM
Imhoopin2 Aball
Imhoopin2 Aball - avatar