★ wanayoo — archive 1999 https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Errors/Typed_array_invalid_argumentsNouvelle recherche | Portail wanayoo

MDN wants to learn about developers like you: https://qsurvey.mozilla.com/s3/MDN-dev-survey

Unsere Freiwilligen haben diesen Artikel noch nicht in Deutsch übersetzt. Machen Sie mit und helfen Sie, das zu erledigen!
Sie können den Artikel auch auf English (US) lesen.

Message

TypeError: invalid arguments (Firefox)

Error type

TypeError

What went wrong?

Typed array constructors require either

  • a length,
  • another typed array,
  • array-like objects,
  • iterable objects or
  • an ArrayBuffer object

to create a new typed array. Other constructor arguments will not create a valid typed array.

Examples

Typed arrays, for example a Uint8Array, can't be constructed from a string. In fact, strings can't be in typed arrays at all.

var ta = new Uint8Array("nope");
// TypeError: invalid arguments

Different ways to create a valid Uint8Array:

// From a length
var uint8 = new Uint8Array(2);
uint8[0] = 42;
console.log(uint8[0]); // 42
console.log(uint8.length); // 2
console.log(uint8.BYTES_PER_ELEMENT); // 1

// From an array
var arr = new Uint8Array([21,31]);
console.log(arr[1]); // 31

// From another TypedArray
var x = new Uint8Array([21, 31]);
var y = new Uint8Array(x);
console.log(y[0]); // 21

// From an ArrayBuffer
var buffer = new ArrayBuffer(8);
var z = new Uint8Array(buffer, 1, 4);

// From an iterable 
var iterable = function*(){ yield* [1,2,3]; }(); 
var uint8 = new Uint8Array(iterable); 
// Uint8Array[1, 2, 3]

See also

Schlagwörter des Dokuments und Mitwirkende

Schlagwörter: 
 Mitwirkende an dieser Seite: fscholz
 Zuletzt aktualisiert von: fscholz,