I was trying to multiply each of the values in an array by 2 and push the value to another array at each loop. I have no idea why the following code seems to triger an infinite loop which crashes the browser. I have other solutions to get the same result but I just wanted to know the root cause behind the crash so please educate me. Thanks!
multipliedBy([1,2,3], 2) //expected result: [1,2,3,2,4,6]
function multipliedBy(arr, num){
var oldArr = arr;
for(var i=0;i<arr.length;i++){
oldArr.push(arr[i] * num);
}
return oldArr;
}