var str = "ahceclwlxo";
for (var i = 1; i <str.length; i+=2){
console.log(str[i]);
}
in my browser again problem, here it shows correct like "hello" but in my browser it shows "he2Lo", where the problem?i am confused really
var str = "ahceclwlxo";
for (var i = 1; i <str.length; i+=2){
console.log(str[i]);
}
in my browser again problem, here it shows correct like "hello" but in my browser it shows "he2Lo", where the problem?i am confused really
What you're seeing in your console is an output of occurrences for each of the console.log
s so the 2l
is really just saying there are two occurrences of l
being logged.
Example Console Output
Here's your code again, but this time with the code being added to an array, then the array being printed.
var str = "ahceclwlxo";
var result = []
for (var i = 1; i <str.length; i+=2){
result.push(str[i])
}
console.log(result)
That prints out (5) ["h", "e", "l", "l", "o"]
in chrome's console. Indicating that you have an array with a length of 5.
Some browsers' console windows are configured to not actually reprint similar outputs repeatedly. Instead they print out the first copy and display the number of repetitions.