Quick Random Value
console.log(
['x', 'y', 'z'][Math.floor(Math.random() * 3)]
);
This will output either x, y
or z
. It works by looking up a random index of an inline array. I find this great for quick prototyping – probably not something you want to be using outside throw away code… Hit the “Try it out…” button and open your dev console.