still learning JS and confused over this
the above code gives out “undefined” as output when it should be “v”
am i missing something or using for-in over a string is the issue
let s="iydafgvb";
var i = 0
for(i in s){
if(s.charAt(i)=="a"){
break;
}
}
console.log(s.charAt(i));
Expecting “v”
but getting “undefined”
New contributor
shivansh sharma is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.