What you get is the expected behavior and while it's not a true endless loop - it's an unproductive loop.
You are adding an element before the current index. This makes the current value to shift so you will start getting x == 3 on each iteration.
This are all premises for an endless loop however JS forEach puts a ceiling on it, and that ceiling is the number of elements present in your original array. No matter how you manipulate the array, it cannot run for more than 8 times, which is the original length.
The output of this code shows best what is happening:
var A = [0, 1, 2, 3, 4, 5, 6, 7]
A.forEach(function(x, index) {
document.writeln('A[' + index + '] = ' + x + '<br/>');
if (x == 3) {
A.splice(1, 0, 'new')
}
})
document.write(JSON.stringify(A));
Output:
A[0] = 0
A[1] = 1
A[2] = 2
A[3] = 3
A[4] = 3
A[5] = 3
A[6] = 3
A[7] = 3
[0,"new","new","new","new","new",1,2,3,4,5,6,7]
Array.forEachis available in the language specification. (Or to see it in JS check the polyfill at MDN.)