I'm trying to obtain a list of all elements that are in a JavaScript array, but I've noticed that using array.toString
does not always show all the contents of the array, even when some elements of the array have been initialized. Is there any way to print each element of an array in JavaScript, along with the corresponding coordinates for each element? I want to find a way to print a list of all coordinates that have been defined in the array, along with the corresponding values for each coordinate.
var coordinates = [];
coordinates[[0, 0, 3, 5]] = "Hello World";
coordinates[[0, 0, 3]] = "Hello World1";
console.log(coordinates[[0, 0, 3]]);
console.log(coordinates[[0, 0, 3, 5]]);
console.log(coordinates.toString()); //this doesn't print anything at all, despite the fact that some elements in this array are defined