I am doing substitution of values in an array as part of my attempt to learn JavaScript coding. As I take the original array and console.log the output, then do my substitution and again console.log the output, I get the same result from both console.log results (e.g. the value of 67 in the original array has been replaced by 73 in both console.log outputs).
Code section in question -
var myNumericalArray = [23,45,67,91];
console.log(myNumericalArray);
myNumericalArray[2] = 73;
console.log(myNumericalArray);
myNumericalArray = [];
console.log(myNumericalArray);
Console.log output result -
Array(4) 0:23 1:45 2:73 3:91 length: 4__proto__: Array(0)
Array(4) 0:23 1:45 2:73 3:91 length: 4__proto__: Array(0)
Array(0)length: 0__proto__: Array(0)
I would have thought the first output would have been 23,45,67,91 and the second one 23,45,73,91. The third console.log output returns an empty array as I would have expected. In fact, I put the third step in under the premise that it would refresh any browser stored values in case that was the reason the 73 showed up in the first array output values; like from previously running the code.
This really is about understanding the processing flow steps and clearing of values in a relatively simple array situation. I have a much more complex code flow calling HTML input form results, grabbing and using function values to pass the values to an API putting METAR aviation weather where the code flow has frustrated me. So I decided to see if I could understand the logic in a much more basic case presented here and I am still stymied in terms of figuring out how initial values are cleared for an updated value to be presented.
Can anyone offer insight on this question around JavaScript flow processing to explain why this result is occurring.