From 074785cea106179cb3305637055ab0a009ca74f2 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:52 -0500 Subject: initial commit --- .../reference/global_objects/string/index.html | 409 +++++++++++++++++++++ .../global_objects/string/indexof/index.html | 200 ++++++++++ .../global_objects/string/startswith/index.html | 96 +++++ .../global_objects/string/tolowercase/index.html | 125 +++++++ .../global_objects/string/touppercase/index.html | 125 +++++++ .../global_objects/string/trim/index.html | 139 +++++++ 6 files changed, 1094 insertions(+) create mode 100644 files/nl/web/javascript/reference/global_objects/string/index.html create mode 100644 files/nl/web/javascript/reference/global_objects/string/indexof/index.html create mode 100644 files/nl/web/javascript/reference/global_objects/string/startswith/index.html create mode 100644 files/nl/web/javascript/reference/global_objects/string/tolowercase/index.html create mode 100644 files/nl/web/javascript/reference/global_objects/string/touppercase/index.html create mode 100644 files/nl/web/javascript/reference/global_objects/string/trim/index.html (limited to 'files/nl/web/javascript/reference/global_objects/string') diff --git a/files/nl/web/javascript/reference/global_objects/string/index.html b/files/nl/web/javascript/reference/global_objects/string/index.html new file mode 100644 index 0000000000..a4847a7626 --- /dev/null +++ b/files/nl/web/javascript/reference/global_objects/string/index.html @@ -0,0 +1,409 @@ +--- +title: String +slug: Web/JavaScript/Reference/Global_Objects/String +tags: + - ECMAScript6 + - JavaScript + - NeedsTranslation + - Reference + - String + - TopicStub +translation_of: Web/JavaScript/Reference/Global_Objects/String +--- +
{{JSRef}}
+ +

The String global object is a constructor for strings, or a sequence of characters.

+ +

Syntax

+ +

String literals take the forms:

+ +
'string text'
+"string text"
+"中文 español English हिन्दी العربية português বাংলা русский 日本語 ਪੰਜਾਬੀ 한국어 தமிழ்"
+ +

Strings can also be created using the String global object directly:

+ +
String(thing)
+
+ +

Parameters

+ +
+
thing
+
Anything to be converted to a string.
+
+ +

Template strings

+ +

Since ECMAScript 2015, string literals can also be so-called Template strings:

+ +
`hello world`
+`hello!
+ world!`
+`hello ${who}`
+escape `<a>${who}</a>`
+ +
+
+ +

Escape notation

+ +

Beside regular, printable characters, special characters can be encoded using escape notation:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CodeOutput
\0the NULL character
\'single quote
\"double quote
\\backslash
\nnew line
\rcarriage return
\vvertical tab
\ttab
\bbackspace
\fform feed
\uXXXXunicode codepoint
\u{X} ... \u{XXXXXX}unicode codepoint {{experimental_inline}}
\xXXthe Latin-1 character
+ +

NOTE: Unlike some other languages, JavaScript makes no distinction between single-quoted strings and double-quoted strings, therefore, the escape sequences above work in strings created with either single or double quotes.

+ +
+
+ +

Long literal strings

+ +

Sometimes, your code will include strings which are very long. Rather than having lines that go on endlessly, or wrap at the whim of your editor, you may wish to specifically break the string into multiple lines in the source code without affecting the actual string contents. There are two ways you can do this.

+ +

You can use the + operator to append multiple strings together, like this:

+ +
let longString = "This is a very long string which needs " +
+                 "to wrap across multiple lines because " +
+                 "otherwise my code is unreadable.";
+
+ +

Or you can use the backslash character ("\") at the end of each line to indicate that the string will continue on the next line. Make sure there is no space or any other character after the backslash (except for a line break), or as an indent; otherwise it will not work. That form looks like this:

+ +
let longString = "This is a very long string which needs \
+to wrap across multiple lines because \
+otherwise my code is unreadable.";
+
+ +

Both of these result in identical strings being created.

+ +

Description

+ +

Strings are useful for holding data that can be represented in text form. Some of the most-used operations on strings are to check their {{jsxref("String.length", "length")}}, to build and concatenate them using the + and += string operators, checking for the existence or location of substrings with the {{jsxref("String.prototype.indexOf()", "indexOf()")}} method, or extracting substrings with the {{jsxref("String.prototype.substring()", "substring()")}} method.

+ +

Character access

+ +

There are two ways to access an individual character in a string. The first is the {{jsxref("String.prototype.charAt()", "charAt()")}} method:

+ +
return 'cat'.charAt(1); // returns "a"
+
+ +

The other way (introduced in ECMAScript 5) is to treat the string as an array-like object, where individual characters correspond to a numerical index:

+ +
return 'cat'[1]; // returns "a"
+
+ +

For character access using bracket notation, attempting to delete or assign a value to these properties will not succeed. The properties involved are neither writable nor configurable. (See {{jsxref("Object.defineProperty()")}} for more information.)

+ +

Comparing strings

+ +

C developers have the strcmp() function for comparing strings. In JavaScript, you just use the less-than and greater-than operators:

+ +
var a = 'a';
+var b = 'b';
+if (a < b) { // true
+  console.log(a + ' is less than ' + b);
+} else if (a > b) {
+  console.log(a + ' is greater than ' + b);
+} else {
+  console.log(a + ' and ' + b + ' are equal.');
+}
+
+ +

A similar result can be achieved using the {{jsxref("String.prototype.localeCompare()", "localeCompare()")}} method inherited by String instances.

+ +

Distinction between string primitives and String objects

+ +

Note that JavaScript distinguishes between String objects and primitive string values. (The same is true of {{jsxref("Boolean")}} and {{jsxref("Global_Objects/Number", "Numbers")}}.)

+ +

String literals (denoted by double or single quotes) and strings returned from String calls in a non-constructor context (i.e., without using the {{jsxref("Operators/new", "new")}} keyword) are primitive strings. JavaScript automatically converts primitives to String objects, so that it's possible to use String object methods for primitive strings. In contexts where a method is to be invoked on a primitive string or a property lookup occurs, JavaScript will automatically wrap the string primitive and call the method or perform the property lookup.

+ +
var s_prim = 'foo';
+var s_obj = new String(s_prim);
+
+console.log(typeof s_prim); // Logs "string"
+console.log(typeof s_obj);  // Logs "object"
+
+ +

String primitives and String objects also give different results when using {{jsxref("Global_Objects/eval", "eval()")}}. Primitives passed to eval are treated as source code; String objects are treated as all other objects are, by returning the object. For example:

+ +
var s1 = '2 + 2';             // creates a string primitive
+var s2 = new String('2 + 2'); // creates a String object
+console.log(eval(s1));        // returns the number 4
+console.log(eval(s2));        // returns the string "2 + 2"
+
+ +

For these reasons, code may break when it encounters String objects when it expects a primitive string instead, although generally authors need not worry about the distinction.

+ +

A String object can always be converted to its primitive counterpart with the {{jsxref("String.prototype.valueOf()", "valueOf()")}} method.

+ +
console.log(eval(s2.valueOf())); // returns the number 4
+
+ +
Note: For another possible approach to strings in JavaScript, please read the article about StringView — a C-like representation of strings based on typed arrays.
+ +

Properties

+ +
+
{{jsxref("String.prototype")}}
+
Allows the addition of properties to a String object.
+
+ +

Methods

+ +
+
{{jsxref("String.fromCharCode()")}}
+
Returns a string created by using the specified sequence of Unicode values.
+
{{jsxref("String.fromCodePoint()")}} {{experimental_inline}}
+
Returns a string created by using the specified sequence of code points.
+
{{jsxref("String.raw()")}} {{experimental_inline}}
+
Returns a string created from a raw template string.
+
+ +

String generic methods

+ +
+

String generics are non-standard, deprecated and will get removed near future. Note that you can not rely on them cross-browser without using the shim that is provided below.

+
+ +

The String instance methods are also available in Firefox as of JavaScript 1.6 (not part of the ECMAScript standard) on the String object for applying String methods to any object:

+ +
var num = 15;
+console.log(String.replace(num, /5/, '2'));
+
+ +

{{jsxref("Global_Objects/Array", "Generics", "#Array_generic_methods", 1)}} are also available on {{jsxref("Array")}} methods.

+ +

The following is a shim to provide support to non-supporting browsers:

+ +
/*globals define*/
+// Assumes all supplied String instance methods already present
+// (one may use shims for these if not available)
+(function() {
+  'use strict';
+
+  var i,
+    // We could also build the array of methods with the following, but the
+    //   getOwnPropertyNames() method is non-shimable:
+    // Object.getOwnPropertyNames(String).filter(function(methodName) {
+    //   return typeof String[methodName] === 'function';
+    // });
+    methods = [
+      'quote', 'substring', 'toLowerCase', 'toUpperCase', 'charAt',
+      'charCodeAt', 'indexOf', 'lastIndexOf', 'startsWith', 'endsWith',
+      'trim', 'trimLeft', 'trimRight', 'toLocaleLowerCase',
+      'toLocaleUpperCase', 'localeCompare', 'match', 'search',
+      'replace', 'split', 'substr', 'concat', 'slice'
+    ],
+    methodCount = methods.length,
+    assignStringGeneric = function(methodName) {
+      var method = String.prototype[methodName];
+      String[methodName] = function(arg1) {
+        return method.apply(arg1, Array.prototype.slice.call(arguments, 1));
+      };
+    };
+
+  for (i = 0; i < methodCount; i++) {
+    assignStringGeneric(methods[i]);
+  }
+}());
+
+ +

String instances

+ +

Properties

+ +
{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/prototype', 'Properties')}}
+ +

Methods

+ +

Methods unrelated to HTML

+ +
{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/prototype', 'Methods_unrelated_to_HTML')}}
+ +

HTML wrapper methods

+ +
{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/prototype', 'HTML_wrapper_methods')}}
+ +

Examples

+ +

String conversion

+ +

It's possible to use String as a "safer" {{jsxref("String.prototype.toString()", "toString()")}} alternative, as although it still normally calls the underlying toString(), it also works for {{jsxref("null")}} and {{jsxref("undefined")}}. For example:

+ +
var outputStrings = [];
+for (var i = 0, n = inputValues.length; i < n; ++i) {
+  outputStrings.push(String(inputValues[i]));
+}
+
+ +

Specifications

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES1')}}{{Spec2('ES1')}}Initial definition.
{{SpecName('ES5.1', '#sec-15.5', 'String')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-string-objects', 'String')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-string-objects', 'String')}}{{Spec2('ESDraft')}} 
+ +

Browser compatibility

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{CompatChrome("1")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
\u{XXXXXX}{{CompatUnknown}}{{CompatGeckoDesktop("40")}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
\u{XXXXXX}{{CompatUnknown}}{{CompatUnknown}}{{CompatGeckoMobile("40")}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +

See also

+ + diff --git a/files/nl/web/javascript/reference/global_objects/string/indexof/index.html b/files/nl/web/javascript/reference/global_objects/string/indexof/index.html new file mode 100644 index 0000000000..efb0b0937f --- /dev/null +++ b/files/nl/web/javascript/reference/global_objects/string/indexof/index.html @@ -0,0 +1,200 @@ +--- +title: String.prototype.indexOf() +slug: Web/JavaScript/Reference/Global_Objects/String/indexOf +tags: + - JavaScript + - Method + - Prototype + - Reference + - String +translation_of: Web/JavaScript/Reference/Global_Objects/String/indexOf +--- +
{{JSRef}}
+ +

De indexOf() methode geeft de positie van het eerste voorval van searchValue binnen het {{jsxref("String")}} object waarop het wordt aangeroepen, waarbij begonnen wordt met zoeken vanaf fromIndex. Geeft -1 terug als geen voorvallen van searchValue gevonden worden.

+ +

Syntaxis

+ +
str.indexOf(searchValue[, fromIndex])
+ +

Parameters

+ +
+
searchValue
+
De string om naar te zoeken.
+
fromIndex {{optional_inline}}
+
De index vanaf waar gezocht moet worden binnen de string. Dit kan elke integer zijn. De standaard waarde is 0, waardoor de hele string wordt doorzocht. Als fromIndex < 0 is wordt de hele string doorzocht. Als fromIndex >= str.length is wordt de string niet doorzocht en wordt -1 teruggegeven. (behalve als searchValue een lege string is, dan wordt str.length teruggegeven)
+
+ +

Return waarde

+ +

De index waarop de gespecificeerde waarde het eerst voorkomt in de string; -1 als die niet gevonden wordt.

+ +

Beschrijving

+ +

Karakters in een string zijn geïndexeerd van links naar rechts. De index van het eerste karakter is 0 en de index van het laatste karakter van een string genaamd stringName is stringName.length - 1.

+ +
'Blue Whale'.indexOf('Blue');     // geeft 0 terug
+'Blue Whale'.indexOf('Blute');    // geeft -1 terug
+'Blue Whale'.indexOf('Whale', 0); // geeft 5 terug
+'Blue Whale'.indexOf('Whale', 5); // geeft 5 terug
+'Blue Whale'.indexOf('', 9);      // geeft 9 terug
+'Blue Whale'.indexOf('', 10);     // geeft 10 terug
+'Blue Whale'.indexOf('', 11);     // geeft 11 terug
+
+ +

Hoofdlettergevoeligheid

+ +

De indexOf() methode is hoofdlettergevoelig. Het volgende voorbeeld geeft -1 terug:

+ +
'Blue Whale'.indexOf('blue'); // geeft -1 terug
+
+ +

Voorvallen controleren

+ +

Onthoudt dat '0' niet vertaalt naar true en '-1' niet vertaalt naar false. Hierdoor moet op de volgende manier gekeken worden of een string binnen een andere string zit:

+ +
'Blue Whale'.indexOf('Blue') !== -1; // true
+'Blue Whale'.indexOf('Bloe') !== -1; // false
+
+ +

Examples

+ +

indexOf() en lastIndexOf() gebruiken

+ +

Het volgende voorbeeld gebruikt indexOf() en {{jsxref("String.prototype.lastIndexOf()", "lastIndexOf()")}} om waardes binnen de string  "Brave new world" te vinden.

+ +
var anyString = 'Brave new world';
+
+console.log('De index van de eerste w vanaf het begin is ' + anyString.indexOf('w'));
+// logs 8
+console.log('De index van de eerste w vanaf het begin is ' + anyString.lastIndexOf('w'));
+// logs 10
+
+console.log('De index van "new" vanaf het begin is ' + anyString.indexOf('new'));
+// logs 6
+console.log('De index van "new" vanaf het eind is ' + anyString.lastIndexOf('new'));
+// logs 6
+
+ +

indexOf() en hoofdlettergevoeligheid

+ +

Het volgende voorbeeld legt twee string variabelen vast. Deze variabelen bevatten dezelfde string, behalve dat de tweede string hoofdletters bevat. De eerste {{domxref("console.log()")}} methode geeft 19 terug. Omdat de indexOf() methode hoofdlettergevoelig is, wordt de string "cheddar" niet gevonden in myCapString, dus de tweede console.log() methode geeft -1 terug.

+ +
var myString    = 'brie, pepper jack, cheddar';
+var myCapString = 'Brie, Pepper Jack, Cheddar';
+
+console.log('myString.indexOf("cheddar") geeft ' + myString.indexOf('cheddar'));
+// geeft 19
+console.log('myCapString.indexOf("cheddar") geeft ' + myCapString.indexOf('cheddar'));
+// geeft -1
+
+ +

indexOf() gebruiken om voorvallen van een letter in een string te tellen

+ +

In het volgende voorbeeld wordt in count de hoeveelheid voorvallen van e in de string str bijgehouden:

+ +
var str = 'To be, or not to be, that is the question.';
+var count = 0;
+var pos = str.indexOf('e');
+
+while (pos !== -1) {
+  count++;
+  pos = str.indexOf('e', pos + 1);
+}
+
+console.log(count); // geeft 4
+
+ +

Specificaties

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SpecificatieStatusOpmerking
{{SpecName('ES1')}}{{Spec2('ES1')}}Eerste definitie.
{{SpecName('ES5.1', '#sec-15.5.4.7', 'String.prototype.indexOf')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-string.prototype.indexof', 'String.prototype.indexOf')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-string.prototype.indexof', 'String.prototype.indexOf')}}{{Spec2('ESDraft')}} 
+ +

Browser compatibiliteit

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

Zie ook

+ + diff --git a/files/nl/web/javascript/reference/global_objects/string/startswith/index.html b/files/nl/web/javascript/reference/global_objects/string/startswith/index.html new file mode 100644 index 0000000000..b183929746 --- /dev/null +++ b/files/nl/web/javascript/reference/global_objects/string/startswith/index.html @@ -0,0 +1,96 @@ +--- +title: String.prototype.startsWith() +slug: Web/JavaScript/Reference/Global_Objects/String/startsWith +tags: + - Begin + - JavaScript + - Méthode + - String +translation_of: Web/JavaScript/Reference/Global_Objects/String/startsWith +--- +
{{JSRef}}
+ +

De startsWith() methode bepaalt of een string begint met de karakters van een bepaalde string. Deze geeft true of false terug waar nodig.

+ +

Syntax

+ +
str.startsWith(zoekString[, positie])
+ +

Parameters

+ +
+
zoekString
+
De karakters om te zoeken aan het begin van de string.
+
positie{{optional_inline}}
+
De positie in de string waar je start met zoeken naar zoekString; start standaard op 0.
+
+ +

Resultaat

+ +

true als de karakters teruggevonden worden aan het begin van de string, anders false.

+ +

Beschrijving

+ +

Deze methde laat je nagaan of een string begint met een andere string. Dit is hoofdletter gevoelig

+ +

Voorbeelden

+ +

Gebruik startsWith()

+ +
//startswith
+var str = 'Te nemen of te laten.';
+
+console.log(str.startsWith('Te nemen'));         // true
+console.log(str.startsWith('te laten'));     // false
+console.log(str.startsWith('te laten', 12)); // true
+
+ +

Polyfill

+ +

Deze methode is toegevoegd aan de ECMAScript 2015 specificaties en is misschien nog niet beschikbaar in alle JavaScript implementaties. Je kan wel Polyfill  String.prototype.startsWith() alsvolgt gebruiken

+ +
if (!String.prototype.startsWith) {
+	String.prototype.startsWith = function(search, pos) {
+		return this.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;
+	};
+}
+
+ +

Een meer degelijke en geoptimaliseerde Polyfill is beschikbaar op GitHub door Mathias Bynens.

+ +

Specificaties

+ + + + + + + + + + + + + + + + + + + +
SpecificatieStatusCommentaar
{{SpecName('ES2015', '#sec-string.prototype.startswith', 'String.prototype.startsWith')}}{{Spec2('ES2015')}}Eerste definitie.
{{SpecName('ESDraft', '#sec-string.prototype.startswith', 'String.prototype.startsWith')}}{{Spec2('ESDraft')}} 
+ +

Browser compatibiliteit

+ + + +

{{Compat("javascript.builtins.String.startsWith")}}

+ +

Meer lezen

+ + diff --git a/files/nl/web/javascript/reference/global_objects/string/tolowercase/index.html b/files/nl/web/javascript/reference/global_objects/string/tolowercase/index.html new file mode 100644 index 0000000000..4716e5afa5 --- /dev/null +++ b/files/nl/web/javascript/reference/global_objects/string/tolowercase/index.html @@ -0,0 +1,125 @@ +--- +title: String.prototype.toLowerCase() +slug: Web/JavaScript/Reference/Global_Objects/String/toLowerCase +tags: + - JavaScript + - Method + - Prototype + - Reference + - String +translation_of: Web/JavaScript/Reference/Global_Objects/String/toLowerCase +--- +
{{JSRef}}
+ +

De toLowerCase() methode geeft een string terug waarbij de meegegeven string naar kleine letters is geconverteerd.

+ +

Syntax

+ +
str.toLowerCase()
+ +

Returnwaarde

+ +

Een nieuwe string waarbij de meegegeven string naar kleine letters is geconverteerd.

+ +

Beschrijving

+ +

De toLowerCase() methode geeft een string terug waarbij de meegegeven string naar kleine letters is geconverteerd. toLowerCase() past de waarde van de meegegeven string str niet aan.

+ +

Examples

+ +

Gebruik van toLowerCase()

+ +
console.log('ALFABET'.toLowerCase()); // 'alfabet'
+
+ +

Specificaties

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SpecificatieStatusOpmerking
{{SpecName('ES1')}}{{Spec2('ES1')}}Initiële definitie. Geïmplementeerd in JavaScript 1.0.
{{SpecName('ES5.1', '#sec-15.5.4.16', 'String.prototype.toLowerCase')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-string.prototype.tolowercase', 'String.prototype.toLowerCase')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-string.prototype.tolowercase', 'String.prototype.toLowerCase')}}{{Spec2('ESDraft')}} 
+ +

Browsercompatibiliteit

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basisondersteuning{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basisondersteuning{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

Zie ook

+ + diff --git a/files/nl/web/javascript/reference/global_objects/string/touppercase/index.html b/files/nl/web/javascript/reference/global_objects/string/touppercase/index.html new file mode 100644 index 0000000000..32393e3c86 --- /dev/null +++ b/files/nl/web/javascript/reference/global_objects/string/touppercase/index.html @@ -0,0 +1,125 @@ +--- +title: String.prototype.toUpperCase() +slug: Web/JavaScript/Reference/Global_Objects/String/toUpperCase +tags: + - JavaScript + - Method + - Prototype + - Reference + - String +translation_of: Web/JavaScript/Reference/Global_Objects/String/toUpperCase +--- +
{{JSRef}}
+ +

De toUpperCase() methode geeft een string terug waarbij de meegegeven string naar hoofdletters is geconverteerd.

+ +

Syntax

+ +
str.toUpperCase()
+ +

Returnwaarde

+ +

Een nieuwe string waarbij de meegegeven string naar hoofdletters is geconverteerd.

+ +

Beschrijving

+ +

De toUpperCase() methode geeft een string terug waarbij de meegegeven string naar hoofdletters is geconverteerd.. toUpperCase() past de waarde van de meegegeven string niet aan.

+ +

Voorbeelden

+ +

Gebruik van toUpperCase()

+ +
console.log('alfabet'.toUpperCase()); // 'ALFABET'
+
+ +

Specificaties

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SpecificatieStatusComment
{{SpecName('ES1')}}{{Spec2('ES1')}}Initiële definitie. Geïmplementeerd in JavaScript 1.0.
{{SpecName('ES5.1', '#sec-15.5.4.18', 'String.prototype.toUpperCase')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-string.prototype.touppercase', 'String.prototype.toUpperCase')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-string.prototype.touppercase', 'String.prototype.toUpperCase')}}{{Spec2('ESDraft')}} 
+ +

Browsercompatibiliteit

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basisondersteuning{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basisondersteuning{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

Zie ook

+ + diff --git a/files/nl/web/javascript/reference/global_objects/string/trim/index.html b/files/nl/web/javascript/reference/global_objects/string/trim/index.html new file mode 100644 index 0000000000..c595279b0d --- /dev/null +++ b/files/nl/web/javascript/reference/global_objects/string/trim/index.html @@ -0,0 +1,139 @@ +--- +title: String.prototype.trim() +slug: Web/JavaScript/Reference/Global_Objects/String/Trim +tags: + - ECMAScript6 + - JavaScript + - Method + - Prototype + - Reference + - String +translation_of: Web/JavaScript/Reference/Global_Objects/String/Trim +--- +
{{JSRef}}
+ +

De trim() methode verwijdert witruimte aan het begin en einde van een string. Witruimte betreft in deze context alle whitespace karakters (spatie, tab, no-break spatie, etc.) en alle regeleindekarakters (LF, CR, etc.).

+ +

Syntax

+ +
str.trim()
+ +

Returnwaarde

+ +

Een nieuwe string waarbij de meegegeven string geen witruimte aan beide kanten meer heeft.

+ +

Beschrijving

+ +

De trim() methode geeft een string terug waarvan aan het begin en einde de witruimte is afgestript. trim() past de waarde van de string zelf niet aan.

+ +

Voorbeelden

+ +

Het gebruik van trim()

+ +

Het volgende voorbeeld toont de string 'foo':

+ +
var orig = '   foo  ';
+console.log(orig.trim()); // 'foo'
+
+// Ander voorbeeld .trim() voor het verwijderen van witruimte aan een kant.
+
+var orig = 'foo    ';
+console.log(orig.trim()); // 'foo'
+
+ +

Polyfill

+ +

Roep de volgende code aan voor het aanroepen van andere code, om trim() beschikbaar te maken als deze nog niet oorspronkelijk ondersteund werd.

+ +
if (!String.prototype.trim) {
+  String.prototype.trim = function () {
+    return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
+  };
+}
+
+ +

Specificaties

+ + + + + + + + + + + + + + + + + + + + + + + + +
SpecificatieStatusOpmerking
{{SpecName('ES5.1', '#sec-15.5.4.20', 'String.prototype.trim')}}{{Spec2('ES5.1')}}Initiële definitie. Geïmplementeerd in JavaScript 1.8.1.
{{SpecName('ES6', '#sec-string.prototype.trim', 'String.prototype.trim')}}{{Spec2('ES6')}}
{{SpecName('ESDraft', '#sec-string.prototype.trim', 'String.prototype.trim')}}{{Spec2('ESDraft')}}
+ +

Browsercompatibiliteit

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basisondersteuning{{CompatVersionUnknown}}{{CompatGeckoDesktop("1.9.1")}}{{CompatIE("9")}}{{CompatOpera("10.5")}}{{CompatSafari("5")}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basisondersteuning{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

Zie ook

+ + -- cgit v1.2.3-54-g00ecf