I am attempting to distinguish between single clicks (assigned value 0) and double clicks (assigned value 1), while also keeping a log of the click and its position in a map. However, I have noticed that the keys are automatically sorted in ascending order, even though I did not intentionally sort them. Is there a way to incorporate the position key along with the corresponding value of 1 or 0 at the end while ensuring that all clicks are properly recorded? I even attempted converting the key to a string using String(i)
.
If you'd like to see the entire code for the project I'm currently working on, it can be found here: Codesandbox
var lastClicked;
var map = {};
var grid = clickableGrid(20, 30, function(el, row, col, i, isDoubleClick) {
if (!isDoubleClick && !el.className) {
el.className = "clicked";
map[String(i)] = 0;
} else if (isDoubleClick && !el.className) {
el.className = "niclicked";
map[String(i)] = 1;
}
console.log(map);
});
document.body.appendChild(grid);