Here is a sample of what doesn’t work:
var array_one = [];
array_one=['a','b','c'];
Declaring and populating the array outside any function doesn’t work, but
var array_one = [];
function do_something(){
array_one=['a','b','c'];
}
does, because it’s inside a function. Why?
array_one['a','b','b']is not syntax to populate an array – I’m not really sure what it does actually.If you do
array_one = ['a','b','c']then you replace the variable with a new array. (The difference between this and populating an array is that other references to the previous array will still have the old value.)To add values to the array, use
array_one.push('a').