Sie sind nicht angemeldet.


|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"[url]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/url]
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
<head>
<meta http-equiv="Content-Script-Type" content="text/javascript"/>
<title>JavaScript</title>
</head>
<body>
<h1>JavaScript</h1>
<script type="text/javascript">
// Array erstellen
person = ['Klaus', 'Trophob', '01.02.1975', 185, 70];
// Array durchlaufen
anzahlTexte = 0;
anzahlZahlen = 0;
str = ''; // *1
for (i in person) {
// Wert an String anhängen
str += ' ' + person[i]; // *1
// Typ abfragen
type = typeof(person[i]);
if (type == 'string') {
anzahlTexte++;
} else if (type == 'number') {
anzahlZahlen++;
}
}
document.write('Inhalt des Feldes:' + str + '<br/>\n'); // *1
document.write('Inhalt des Feldes: ' + person.join(' ') + '<br/>\n'); // deutlich schneller und kürzer als *1
document.write('Anzahl der Text-Elemente: ' + anzahlTexte + '<br/>\n');
document.write('Anzahl der Zahlen-Elemente: ' + anzahlZahlen + '<br/>\n');
</script>
</body>
</html>
|
Zitat von »BloodHound«
danke![]()
-