Is there a way to set every element of a Javascript typed array (i.e. a Uint32Array) to some value (something like the C function memset would do)?
var foo = new Uint32Array(16384);
for (int i=0; i<foo.length; i++) { // I want to do this without a for-loop
foo[i] = 0xdeadbeef;
}
Generally, the answer in this case is going to be no. In JavaScript you either declare things fully when you create them via literal syntax:
Or you assign values to them (via loops when necessary for sequences):
JavaScript is a language that benefits from only accessing Arr2.length once when possible, so this syntax should net a performance benefit over other variations, but there’s not a way to assign all positions in an array to a specific value other than undefined, which is what you get when you initialize with a size.