Dear experts and gurus,
The more I read the more I am confused. Every now and then the talk is "JS Arrays are objects and hence they are passed by reference". However, simple experiments leave my puzzled: It's the same as with light (depending on the view it behaves as waves or as particles):
gaSomething = ["a","b", "c"]; Update (gaSomething); alert (gaSomething.join("\n")); // the global array has changed DeleteItem (gaSomething, "7"); alert (gaSomething.join("\n")); // the global array has not changed function Update (array) { for (var j= 0; j < 9; j++) { array.push(j+1); } } function DeleteItem (array, item) { var index = IsInArray (array, item); var lower = array.slice (0, index); // lower part var upper = array.slice (index+1); // upper part var locArray = lower.concat(upper); array = locArray; // transfer data alert ("in DeleteItem:\n" + array.join("\n")); }
The only safe assumption is that JS arrays are not treated as objects and hence are passed by value. This makes it difficult to set up functions to delete items from various arrays - for each array a distinct function is needed!
Any ideas for a general DeleteItem function ?