bharadwajt10 bharadwajt10 - 1 year ago 74
Javascript Question

Why my code snaps off the browser window when ran in console?

When I ran the code in browser console or in js fiddle, this code snaps off the browser. I don't understand why it does. Can some one show some light ?

var sample = [1, 2, 3, 4];

function arrDupli(sample) {
var mysample = sample;
for (var i = 0; i < sample.length; i++) {


Answer Source

you are creating an infinite loop, mysample and sample have both the same value, so you are basically just pushing the same value over and over.

Try creating and empty array instead var mysample = [];

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download