Hallo,
auf dieser Seite findet man folgende Information: https://www.w3schools.com/js/js_arrays.asp
Es wird hier gesagt, dass JS keine assoziativen Arrays unterstützt und im nächsten Abschnitt wird erklärt, wann man nummerierte und wann man "named" Indices verwendet.
Das ist doch ein Widerspruch?
auf dieser Seite findet man folgende Information: https://www.w3schools.com/js/js_arrays.asp
JavaScript does not support arrays with named indexes.
In JavaScript, arrays always use numbered indexes.
WARNING !!
If you use named indexes, JavaScript will redefine the array to a standard object.
After that, some array methods and properties will produce incorrect results.
Code:
var person = [];
person["firstName"] = "John";
person["lastName"] = "Doe";
person["age"] = 46;
var x = person.length; // person.length will return 0
var y = person[0]; // person[0] will return undefined
In JavaScript, arrays use numbered indexes.
In JavaScript, objects use named indexes.
JavaScript does not support associative arrays.
You should use objects when you want the element names to be strings (text).
You should use arrays when you want the element names to be numbers.
Es wird hier gesagt, dass JS keine assoziativen Arrays unterstützt und im nächsten Abschnitt wird erklärt, wann man nummerierte und wann man "named" Indices verwendet.
Das ist doch ein Widerspruch?