I’m looking for a way to read from an external text file map.txt (allocated in my own server, not in the client’s computer) and to store the data contained in it in a bi-dimensional array map[][] using Javascript.
The map.txt file would be filled with numbers and each of it’s rows has a fixed length:
21123301201200
12030201303321
22321321021312
12312310001230
12312321221220
So, I want it to store it in the bi-dimensional array map in such a way that map[0][0] = 2 and map[13][4] = 0 -in this example-. Is this even possible to do? And if so, how is it done?
Thanks!
You could use
XMLHttpRequestto get the file. Have a look at: http://www.quirksmode.org/js/xmlhttp.htmlAnd use this function to create the array:
This function should return:
Use
map[4][13]instead ofmap[13][4]to get the last element in your example