js 1d index to 2d coord

JavaScript
y = index / width;
x = index % width;index = x + width * y;
Source

Also in JavaScript: