0

If i want to tell e=any elements of Array c what function can i use?

var a =confirm ("are you curious? if yes tap ok " ); if (a==true ){ alert ("ok done you can ask me you \'what is\'question "); }else { alert ("oh!you should be a curious student ");} var b=prompt ("ask your what's question here -- \n what is --", ""); var c =new Array (" cat "," bat"); var e=c; if (b==e){ alert ("animal is a creature ");

3rd Oct 2020, 3:36 AM
RD:programmer
RD:programmer - avatar
6 odpowiedzi
+ 4
Rinku Das i didn't remember the difference myself so i searched it, this is the answer, function loop() { for (var i = 0; i < 5; i++) { // } console.log(i) // 5 // i'm accessing i after for loop has ended, it would still work coz it is var, and var is function scoped, so you can access it anywhere after it is declared inside the function, but let is block scoped. Using the same example but with let, you won't be able to access i after the loop coz it was declared just for that block. } Using let: for(let i = 0; i < 5; i++){ // } console.log(i); // i is undefined Learnt it from this video, you can check it out for better understanding, https://youtu.be/XgSjoHgy3Rk
3rd Oct 2020, 9:14 PM
maf
maf - avatar
+ 4
ohk, look, if theres an array let a = [ 1, 2, 3, 4, 5 ] and you wanna see that if that array has 4 inside it or not, you can do, if (a.includes(4)){ console.log("Yeah 4 is there") } else { console.log("4 is not there") }
3rd Oct 2020, 3:43 AM
maf
maf - avatar
+ 2
if c.includes(e) would tell you that if e is equal to any element inside array c, if that's what you're asking. You can also use "some" function to which returns true even if a single item in the array passes the checks let result = c.some(item => item === c)
3rd Oct 2020, 3:39 AM
maf
maf - avatar
+ 1
Friend can you give me example
3rd Oct 2020, 3:41 AM
RD:programmer
RD:programmer - avatar
+ 1
V.v.v.v.v. thanks you brother ... You help me a lot .................. Can you tell me the different between var and let !!!!
3rd Oct 2020, 12:19 PM
RD:programmer
RD:programmer - avatar
0
I can not understood still
3rd Oct 2020, 3:41 AM
RD:programmer
RD:programmer - avatar