Array dimension


Hi, everybody.

I have a question about next code. As you can see, the first variable is string, but, it is changed to an array in the condition "if", so, why does it occcur?

var text text = "Blah blah blah blah blah blah Yeison \
blah blah blah Eric blah blah Eric blah blah \
blah blah blah blah blah Eric";

var myName = "Yeison";
var hits = [];

// Look for "E" in the text
for(var i = 0; i < text.length; i++) {
	if (text[i] === "Y") {
		// If we find it, add characters up to
		// the length of my name to the array
		for(var j = i; j < (myName.length + i); j++) {

if (hits.length === 0) {
	console.log("Your name wasn't found!");
} else {


Invalid: unexpected identifier error.

var text = "...";

It is not change to an array, though it may appear as such owing that the indexing is the same for all iterables.




We are working with strings, only.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.