aboutsummaryrefslogtreecommitdiff
path: root/files/de/web/javascript/reference/global_objects/string/lastindexof/index.html
blob: b6c6f3a5489304ad201e094e50179150a06313d1 (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
---
title: String.prototype.lastIndexOf()
slug: Web/JavaScript/Reference/Global_Objects/String/lastIndexOf
translation_of: Web/JavaScript/Reference/Global_Objects/String/lastIndexOf
---
<div>{{JSRef("Global_Objects", "String")}}</div>

<h2 id="Summary" name="Summary">Zusammenfassung</h2>

<p>Die <strong><code>lastIndexOf()</code></strong> Methode gibt den Index des letzten Vorkommnisses des angegebenen Wertes innerhalb des aufrufenden {{jsxref("Global_Objects/String", "Strings")}} Objekts zurück, oder -1, wenn der Wert nicht gefunden wurde. Der aufrufende String wird rückwärts durchsucht, beginnend beim <code>fromIndex</code></p>

<h2 id="Syntax" name="Syntax">Syntax</h2>

<pre class="syntaxbox"><code><var>str</var>.lastIndexOf(<var>searchValue</var>[, <var>fromIndex</var>])</code></pre>

<h3 id="Parameters" name="Parameters">Parameter</h3>

<dl>
 <dt><code>searchValue</code></dt>
 <dd>Ein String mit dem Wert, nach dem gesucht werden soll.</dd>
 <dt><code>fromIndex</code></dt>
 <dd>Optional. Die Position im aufrufenden String, ab der gesucht rückwärts werden soll. The Position wird gezählt von links nach rechts. Gesucht wird von dieser Position ab nach links. Diese kann jeden Integerwert annehmen. Der Standartwert ist <code>str.length</code>. Wenn der Wert negativ ist, wird 0 verwendet. Wenn <code>fromIndex &gt; str.length</code>, wird <code>str.length </code>statt <code>fromIndex</code> benutzt.</dd>
</dl>

<h2 id="Description" name="Description">Beschreibung</h2>

<p>Zeichen in einem String werden von links nach rechts gezählt. Der Index des ersten Zeichens ist 0, der Index des letzten Zeichens ist <code>stringName.length - 1</code>.</p>

<pre class="brush: js">'canal'.lastIndexOf('a');     // returns 3
'canal'.lastIndexOf('a', 2);  // returns 1
'canal'.lastIndexOf('a', 0);  // returns -1
'canal'.lastIndexOf('x');     // returns -1
</pre>

<h3 id="Case-sensitivity" name="Case-sensitivity">Groß- und Kleinschreibung</h3>

<p>Die <code>lastIndexOf() </code>Methode unterscheidet zwischen Groß- und Kleinschreibung. Der folgende Ausdruck gibt zum Beispiel <code>-1</code> zurück.</p>

<pre class="brush: js">'Blue Whale, Killer Whale'.lastIndexOf('blue'); // returns -1
</pre>

<h2 id="Examples" name="Examples">Beispiele</h2>

<h3 id="Example:_Using_indexOf_and_lastIndexOf" name="Example:_Using_indexOf_and_lastIndexOf">Beispiel: Benutzung von <code>indexOf()</code> und <code>lastIndexOf()</code></h3>

<p>Das folgende Beispiel verwendet {{jsxref("String.prototype.indexOf()", "indexOf()")}} und <code>lastIndexOf(),</code> um Werte im String <code>"Brave new world" zu finden</code>.</p>

<pre class="brush: js">var anyString = 'Brave new world';

console.log('The index of the first w from the beginning is ' + anyString.indexOf('w'));
// Displays 8
console.log('The index of the first w from the end is ' + anyString.lastIndexOf('w'));
// Displays 10

console.log('The index of "new" from the beginning is ' + anyString.indexOf('new'));
// Displays 6
console.log('The index of "new" from the end is ' + anyString.lastIndexOf('new'));
// Displays 6
</pre>

<h2 id="Spezifikationen">Spezifikationen</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>ECMAScript 1st Edition.</td>
   <td>Standard</td>
   <td>Initial definition.</td>
  </tr>
  <tr>
   <td>{{SpecName('ES5.1', '#sec-15.5.4.8', 'String.prototype.lastIndexOf')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-string.prototype.lastindexof', 'String.prototype.lastIndexOf')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="Browserkompatibilität">Browserkompatibilität</h2>

<div>{{CompatibilityTable}}</div>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Chrome for Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="See_also" name="See_also">Links</h2>

<ul>
 <li>{{jsxref("String.prototype.charAt()")}}</li>
 <li>{{jsxref("String.prototype.indexOf()")}}</li>
 <li>{{jsxref("String.prototype.split()")}}</li>
 <li>{{jsxref("Array.prototype.indexOf()")}}</li>
 <li>{{jsxref("Array.prototype.lastIndexOf()")}}</li>
</ul>