I tried copying an array of objects and i failed terribly. Every time I ended up with an array of references to original aray.
I tried ".concat()", I used "for" copying every element separately, but every time I made change in temporary array, original array changed too.
Here's the code.
Glossary:
tablicaZnacznikow - original array
placeholder - temporary array
tempClosest - id of closest marker
startingPointID - id of marker from witch i start calculation
.meta field - defines if marker has been added to polyline
var placeholder = tablicaZnacznikow.concat();
var tempArrayOfSomething = [placeholder[startingPointID].latLng];
for (var i = 0; i < placeholder.length; i++) {
var tempClosest = findClosestMarkerToAnotherMarker(placeholder, startingPointID);
tempArrayOfSomething.push(placeholder[tempClosest].latLng);
startingPointID = tempClosest;
placeholder[tempClosest].meta = "USED";
console.log(tempClosest);
}
I use this code to make an array for making a path for gMap3 polyline. Thanks in advance.