Files
freeCodeCamp/curriculum/challenges/german/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md
2022-08-19 20:53:29 +02:00

1.8 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
56bbb991ad1ed5201cd392ca Auf Array-Daten mit Indizes zugreifen 1 https://scrimba.com/c/cBZQbTz 16158 access-array-data-with-indexes

--description--

Wir können auf die Daten innerhalb von Arrays mit Indizes zugreifen.

Array-Indizes werden in der gleichen Klammernotation wie Strings geschrieben, außer dass sie anstelle eines Zeichens einen Eintrag im Array spezifizieren. Wie bei Strings verwenden Arrays eine nullbasierte Indizierung, so dass das erste Element in einem Array den Index 0 hat.


Beispiel

const array = [50, 60, 70];
console.log(array[0]);
const data = array[1];

console.log(array[0]) gibt 50 aus, und data hat den Wert 60.

--instructions--

Erstelle eine Variable namens myData und setzte sie, mit Hilfe von Klammernotation, mit dem ersten Wert von myArray gleich.

--hints--

Die Variable myData sollte gleich dem ersten Wert von myArray sein.

assert(
  (function () {
    if (
      typeof myArray !== 'undefined' &&
      typeof myData !== 'undefined' &&
      myArray[0] === myData
    ) {
      return true;
    } else {
      return false;
    }
  })()
);

Die Daten in der Variable myArray sollten mit Hilfe von Klammernotation abgerufen werden.

assert(
  (function () {
    if (code.match(/\s*=\s*myArray\[0\]/g)) {
      return true;
    } else {
      return false;
    }
  })()
);

--seed--

--after-user-code--

if(typeof myArray !== "undefined" && typeof myData !== "undefined"){(function(y,z){return 'myArray = ' + JSON.stringify(y) + ', myData = ' + JSON.stringify(z);})(myArray, myData);}

--seed-contents--

const myArray = [50, 60, 70];


--solutions--

const myArray = [50, 60, 70];
const myData = myArray[0];