Math.random() in javascript is able to return 1, right? Which means if I would be to use it to get a random index on my array the following code could fail:
No, it returns from 0 inclusive to 1 exclusive
See https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Math/random
Note however the caveat in that page:
Note that as numbers in JavaScript are IEEE 754 floating point numbers with round-to-nearest-even behavior, these ranges, excluding the one for Math.random() itself, aren't exact, and depending on the bounds it's possible in extremely rare cases (on the order of 1 in 262) to calculate the usually-excluded upper bound.
For these purposes, though, you should be fine.