Can someone explain to me how is this possible?

When I define global attribute for RegExp pattern, regexp's test method after each true returns false when testing arrays element. When testing string literal returned value is true with the same regexp pattern?

Here's sample code:

	<title> Untitled </title>
	<meta charset="utf-8">
		var myarray = ["xxx","xxx","xxx","xxx"];
		var re = new RegExp("xxx");
		var re2 = new RegExp("xxx","g");
		for (i = 0; i < myarray.length; i++)
			alert(re.test(myarray[i])); //this one returns ture for each array's element as expected
		for (i = 0; i < myarray.length; i++)
			alert(re2.test(myarray[i])); //this one returns false for every second element
		var s = "xxx";
		alert(re2.test(s)); //returns true
Thanks in advance!