programming:javascript:usage
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| programming:javascript:usage [2023/12/06 10:51] – ms | programming:javascript:usage [2023/12/06 11:50] (current) – ms | ||
|---|---|---|---|
| Line 3: | Line 3: | ||
| Ein Objekt gruppiert mehrere Werte zusammen: | Ein Objekt gruppiert mehrere Werte zusammen: | ||
| < | < | ||
| - | const objektEins = { | + | |
| - | | + | name: ' |
| - | | + | |
| - | | + | |
| - | | + | |
| + | tag: 19, | ||
| + | monat: 3, | ||
| + | jahr: 1970 | ||
| + | | ||
| + | }; | ||
| + | |||
| + | console.log(objektEins); | ||
| + | console.log(objektEins.name); | ||
| + | console.log(objektEins[' | ||
| + | console.log(objektEins.alter); | ||
| + | console.log(objektEins.geburtstag); | ||
| + | console.log(objektEins.geburtstag.tag); | ||
| + | console.log(objektEins.geburtstag.monat); | ||
| + | console.log(objektEins.geburtstag.jahr); | ||
| + | |||
| + | > {name: ' | ||
| + | > Hans | ||
| + | > Wurst | ||
| + | > 27 | ||
| + | > {tag: 19, monat: 3, jahr: 1970} | ||
| + | > 19 | ||
| + | > 3 | ||
| + | > 1970 | ||
| + | |||
| + | |||
| + | </ | ||
| + | Neuer Wert in ein bestehendes Objekt hinzufügen: | ||
| + | < | ||
| + | objektEins.wohnort = ' | ||
| console.log(objektEins); | console.log(objektEins); | ||
| + | |||
| + | > {name: ' | ||
| + | > Mainz | ||
| + | </ | ||
| + | |||
| + | Ein Wert aus einem Objekt löschen: | ||
| + | < | ||
| + | delete objektEins.wohnort; | ||
| + | |||
| + | console.log(objektEins); | ||
| + | |||
| + | > {name: ' | ||
| + | </ | ||
| + | Funktionen in Objekten -> Methoden | ||
| + | < | ||
| + | const objektEins = { | ||
| + | name: ' | ||
| + | alter: 27, | ||
| + | methodeEins: | ||
| + | console.log(' | ||
| + | } | ||
| + | }; | ||
| + | |||
| + | console.log(objektEins); | ||
| + | console.log(objektEins.name); | ||
| + | console.log(objektEins.alter); | ||
| + | console.log(objektEins.methodeEins); | ||
| + | |||
| + | objektEins.methodeEins(); | ||
| + | |||
| + | > {name: ' | ||
| + | > Hans | ||
| + | > 27 | ||
| + | > ƒ funktionEins() { | ||
| + | console.log(' | ||
| + | } | ||
| + | > Funktion im Objekt | ||
| + | </ | ||
| + | < | ||
| + | console.log(typeof Math); | ||
| + | console.log(typeof Math.sin); | ||
| + | |||
| + | > object | ||
| + | > function | ||
| </ | </ | ||
programming/javascript/usage.1701856274.txt.gz · Last modified: 2023/12/06 10:51 by ms