js 1d index to 2d coord

Code Example - js 1d index to 2d coord

                
                        y = index / width;
x = index % width;
                    
                
 

how to convert a 2d coordinate to an index

                        
                                index = x + width * y;