Permalink
Please sign in to comment.
Showing
with
633 additions
and 0 deletions.
- +73 −0 Object.getOwnPropertyNames.md
- +63 −0 Object.keys.md
- +35 −0 String.fromCharCode.md
- +47 −0 String.length.md
- +38 −0 js-String-prototype-charAt.md
- +34 −0 js-String-prototype-charCodeAt.md
- +63 −0 js-String-prototype-lastindexOf.md
- +49 −0 js-String-prototype-match.md
- +62 −0 js-String-prototype-replace.md
- +61 −0 js-String-prototype-substr.md
- +59 −0 js-String-prototype-substring.md
- +49 −0 parseInt.md
73
Object.getOwnPropertyNames.md
@@ -0,0 +1,73 @@ | ||
+# Object.getOwnPropertyNames() | ||
+The `Object.getOwnPropertyNames()` method returns an array of all properties (enumerable or not) found directly upon a given object. | ||
+ | ||
+## Syntax | ||
+```js | ||
+Object.getOwnPropertyNames(obj) | ||
+``` | ||
+ | ||
+### Parameters | ||
+ | ||
+**obj** | ||
+ | ||
+The object whose enumerable *and non-enumerable* own properties are to be returned. | ||
+ | ||
+[MDN link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames) | [MSDN link](https://msdn.microsoft.com/en-us/LIBRary/ff688126%28v=vs.94%29.aspx) | ||
+ | ||
+##Description | ||
+`Object.getOwnPropertyNames()` returns an array whose elements are strings corresponding to the enumerable *and non-enumerable* properties found directly upon object. The ordering of the enumerable properties in the array is consistent with the ordering exposed by a `for...in` loop (or by `Object.keys()`) over the properties of the object. The ordering of the non-enumerable properties in the array, and among the enumerable properties, is not defined. | ||
+ | ||
+## Examples | ||
+ | ||
+```js | ||
+var arr = ['a', 'b', 'c']; | ||
+console.log(Object.getOwnPropertyNames(arr).sort()); // logs '0,1,2,length' | ||
+ | ||
+// Array-like object | ||
+var obj = { 0: 'a', 1: 'b', 2: 'c' }; | ||
+console.log(Object.getOwnPropertyNames(obj).sort()); // logs '0,1,2' | ||
+ | ||
+// Logging property names and values using Array.forEach | ||
+Object.getOwnPropertyNames(obj).forEach(function(val, idx, array) { | ||
+ console.log(val + ' -> ' + obj[val]); | ||
+}); | ||
+// logs | ||
+// 0 -> a | ||
+// 1 -> b | ||
+// 2 -> c | ||
+ | ||
+// non-enumerable property | ||
+var my_obj = Object.create({}, { | ||
+ getFoo: { | ||
+ value: function() { return this.foo; }, | ||
+ enumerable: false | ||
+ } | ||
+}); | ||
+my_obj.foo = 1; | ||
+ | ||
+console.log(Object.getOwnPropertyNames(my_obj).sort()); // logs 'foo,getFoo' | ||
+``` | ||
+ | ||
+```js | ||
+function Pasta(grain, size, shape) { | ||
+ this.grain = grain; | ||
+ this.size = size; | ||
+ this.shape = shape; | ||
+} | ||
+ | ||
+var spaghetti = new Pasta("wheat", 2, "circle"); | ||
+ | ||
+var names = Object.getOwnPropertyNames(spaghetti).filter(CheckKey); | ||
+document.write(names); | ||
+ | ||
+// Check whether the first character of a string is 's'. | ||
+function CheckKey(value) { | ||
+ var firstChar = value.substr(0, 1); | ||
+ if (firstChar.toLowerCase() == 's') | ||
+ return true; | ||
+ else | ||
+ return false; | ||
+} | ||
+// Output: | ||
+// size,shape | ||
+``` |
63
Object.keys.md
@@ -0,0 +1,63 @@ | ||
+# Object.keys() | ||
+The `Object.keys()` method returns an array of a given object's own enumerable properties, in the same order as that provided by a `for...in` loop (the difference being that a `for-in` loop enumerates properties in the prototype chain as well). | ||
+ | ||
+## Syntax | ||
+```js | ||
+Object.keys(obj) | ||
+``` | ||
+ | ||
+### Parameters | ||
+ | ||
+**obj** | ||
+ | ||
+The object whose enumerable own properties are to be returned. | ||
+ | ||
+[MDN link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys) | [MSDN link](https://msdn.microsoft.com/en-us/LIBRary/ff688127%28v=vs.94%29.aspx) | ||
+ | ||
+##Description | ||
+`Object.keys()` returns an array whose elements are strings corresponding to the enumerable properties found directly upon object. The ordering of the properties is the same as that given by looping over the properties of the object manually. | ||
+ | ||
+## Examples | ||
+ | ||
+```js | ||
+var arr = ['a', 'b', 'c']; | ||
+console.log(Object.keys(arr)); // console: ['0', '1', '2'] | ||
+ | ||
+// array like object | ||
+var obj = { 0: 'a', 1: 'b', 2: 'c' }; | ||
+console.log(Object.keys(obj)); // console: ['0', '1', '2'] | ||
+ | ||
+// array like object with random key ordering | ||
+var an_obj = { 100: 'a', 2: 'b', 7: 'c' }; | ||
+console.log(Object.keys(an_obj)); // console: ['2', '7', '100'] | ||
+ | ||
+// getFoo is property which isn't enumerable | ||
+var my_obj = Object.create({}, { getFoo: { value: function() { return this.foo; } } }); | ||
+my_obj.foo = 1; | ||
+ | ||
+console.log(Object.keys(my_obj)); // console: ['foo'] | ||
+``` | ||
+ | ||
+```js | ||
+// Create a constructor function. | ||
+function Pasta(grain, width, shape) { | ||
+ this.grain = grain; | ||
+ this.width = width; | ||
+ this.shape = shape; | ||
+ | ||
+ // Define a method. | ||
+ this.toString = function () { | ||
+ return (this.grain + ", " + this.width + ", " + this.shape); | ||
+ } | ||
+} | ||
+ | ||
+// Create an object. | ||
+var spaghetti = new Pasta("wheat", 0.2, "circle"); | ||
+ | ||
+// Put the enumerable properties and methods of the object in an array. | ||
+var arr = Object.keys(spaghetti); | ||
+document.write (arr); | ||
+ | ||
+// Output: | ||
+// grain,width,shape,toString | ||
+``` |
35
String.fromCharCode.md
@@ -0,0 +1,35 @@ | ||
+# String.fromCharCode() | ||
+The static `String.fromCharCode()` method returns a string created by using the specified sequence of Unicode values. | ||
+ | ||
+## Syntax | ||
+```js | ||
+String.fromCharCode(num1[, ...[, numN]]) | ||
+``` | ||
+ | ||
+### Parameters | ||
+ | ||
+ | ||
+**num1, ..., numN** | ||
+ | ||
+A sequence of numbers that are Unicode values. | ||
+ | ||
+[MDN link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode) | [MSDN link](https://msdn.microsoft.com/en-us/LIBRary/wb4w0k66%28v=vs.94%29.aspx) | ||
+ | ||
+ | ||
+##Description | ||
+This method returns a string and not a String object. | ||
+ | ||
+Because `fromCharCode()` is a static method of String, you always use it as `String.fromCharCode()`, rather than as a method of a String object you created. | ||
+ | ||
+## Examples | ||
+ | ||
+```js | ||
+String.fromCharCode(65, 66, 67); // "ABC" | ||
+``` | ||
+ | ||
+```js | ||
+var test = String.fromCharCode(112, 108, 97, 105, 110); | ||
+document.write(test); | ||
+ | ||
+// Output: plain | ||
+``` |
47
String.length.md
@@ -0,0 +1,47 @@ | ||
+# String.length | ||
+The `length` property represents the length of a string. | ||
+ | ||
+## Syntax | ||
+```js | ||
+str.length | ||
+``` | ||
+ | ||
+[MDN link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length) | [MSDN link](https://msdn.microsoft.com/en-us/LIBRary/3d616214%28v=vs.94%29.aspx) | ||
+ | ||
+##Description | ||
+This property returns the number of code units in the string. UTF-16, the string format used by JavaScript, uses a single 16-bit code unit to represent the most common characters, but needs to use two code units for less commonly-used characters, so it's possible for the value returned by length to not match the actual number of characters in the string. | ||
+ | ||
+For an empty string, length is 0. | ||
+ | ||
+The static property `String.length` returns the value 1. | ||
+ | ||
+## Examples | ||
+ | ||
+```js | ||
+var x = 'Mozilla'; | ||
+var empty = ''; | ||
+ | ||
+console.log('Mozilla is ' + x.length + ' code units long'); | ||
+/* "Mozilla is 7 code units long" */ | ||
+ | ||
+console.log('The empty string has a length of ' + empty.length); | ||
+/* "The empty string has a length of 0" */ | ||
+``` | ||
+ | ||
+```js | ||
+var str = "every good boy does fine"; | ||
+ var start = 0; | ||
+ var end = str.length - 1; | ||
+ var tmp = ""; | ||
+ var arr = new Array(end); | ||
+ | ||
+ while (end >= 0) { | ||
+ arr[start++] = str.charAt(end--); | ||
+ } | ||
+ | ||
+// Join the elements of the array with a | ||
+ var str2 = arr.join(''); | ||
+ document.write(str2); | ||
+ | ||
+// Output: enif seod yob doog yreve | ||
+``` |
38
js-String-prototype-charAt.md
@@ -0,0 +1,38 @@ | ||
+# js String prototype charAt | ||
+The `charAt()` method returns the specified character from a string. | ||
+ | ||
+## Syntax | ||
+```js | ||
+str.charAt(index) | ||
+``` | ||
+ | ||
+### Parameters | ||
+ | ||
+**index** | ||
+ | ||
+An integer between 0 and 1-less-than the length of the string. | ||
+ | ||
+[MDN link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt) | [MSDN link](https://msdn.microsoft.com/en-us/LIBRary/65zt5h10%28v=vs.94%29.aspx) | ||
+ | ||
+##Description | ||
+Characters in a string are indexed from left to right. The index of the first character is 0, and the index of the last character in a string called `stringName` is `stringName.length - 1`. If the index you supply is out of range, JavaScript returns an empty string. | ||
+ | ||
+## Examples | ||
+ | ||
+```js | ||
+var anyString = 'Brave new world'; | ||
+ | ||
+console.log("The character at index 0 is '" + anyString.charAt(0) + "'"); // 'B' | ||
+console.log("The character at index 1 is '" + anyString.charAt(1) + "'"); // 'r' | ||
+console.log("The character at index 2 is '" + anyString.charAt(2) + "'"); // 'a' | ||
+console.log("The character at index 3 is '" + anyString.charAt(3) + "'"); // 'v' | ||
+console.log("The character at index 4 is '" + anyString.charAt(4) + "'"); // 'e' | ||
+console.log("The character at index 999 is '" + anyString.charAt(999) + "'"); // '' | ||
+``` | ||
+ | ||
+```js | ||
+var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
+document.write(str.charAt(str.length - 1)); | ||
+ | ||
+// Output: Z | ||
+``` |
34
js-String-prototype-charCodeAt.md
@@ -0,0 +1,34 @@ | ||
+# js String prototype charCodeAt | ||
+The `charCodeAt()` method returns the numeric Unicode value of the character at the given index (except for unicode codepoints > 0x10000). | ||
+ | ||
+## Syntax | ||
+```js | ||
+str.charCodeAt(index) | ||
+``` | ||
+ | ||
+### Parameters | ||
+ | ||
+**index** | ||
+ | ||
+An integer greater than or equal to 0 and less than the length of the string; if it is not a number, it defaults to 0. | ||
+ | ||
+[MDN link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt) | [MSDN link](https://msdn.microsoft.com/en-us/LIBRary/hza4d04f%28v=vs.94%29.aspx) | ||
+ | ||
+##Description | ||
+Note that `charCodeAt()` will always return a value that is less than 65536. This is because the higher code points are represented by a pair of (lower valued) "surrogate" pseudo-characters which are used to comprise the real character. Because of this, in order to examine or reproduce the full character for individual characters of value 65536 and above, for such characters, it is necessary to retrieve not only `charCodeAt(i)`, but also `charCodeAt(i+1)` (as if examining/reproducing a string with two letters). See example 2 and 3 below. | ||
+ | ||
+`charCodeAt()` returns `NaN` if the given `index` is less than 0 or is equal to or greater than the length of the string. | ||
+ | ||
+## Examples | ||
+ | ||
+```js | ||
+'ABC'.charCodeAt(0); // returns 65 | ||
+``` | ||
+ | ||
+```js | ||
+var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
+document.write(str.charCodeAt(str.length - 1)); | ||
+ | ||
+// Output: 90 | ||
+``` | ||
+ |
63
js-String-prototype-lastindexOf.md
@@ -0,0 +1,63 @@ | ||
+# js String prototype lastIndexOf | ||
+The `lastIndexOf()` method returns the index within the calling String object of the last occurrence of the specified value, or -1 if not found. The calling string is searched backward, starting at `fromIndex`. | ||
+ | ||
+## Syntax | ||
+```js | ||
+str.lastIndexOf(searchValue[, fromIndex]) | ||
+``` | ||
+ | ||
+### Parameters | ||
+ | ||
+**searchValue** | ||
+ | ||
+A string representing the value to search for. | ||
+ | ||
+**fromIndex** | ||
+ | ||
+Optional. The location within the calling string to start the search at, indexed from left to right. It can be any integer. The default value is `str.length`. If it is negative, it is treated as 0. If `fromIndex > str.length`, `fromIndex` is treated as `str.length`. | ||
+ | ||
+[MDN link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf) | [MSDN link](https://msdn.microsoft.com/en-us/LIBRary/6d20k718%28v=vs.94%29.aspx) | ||
+ | ||
+##Returns | ||
+Returns the last occurrence of a substring in the string. | ||
+ | ||
+##Description | ||
+Characters in a string are indexed from left to right. The index of the first character is 0, and the index of the last character is `stringName.length - 1`. | ||
+ | ||
+The `lastIndexOf()` method is case sensitive. For example, the following expression returns `-1`: | ||
+ | ||
+## Examples | ||
+ | ||
+```js | ||
+'canal'.lastIndexOf('a'); // returns 3 | ||
+'canal'.lastIndexOf('a', 2); // returns 1 | ||
+'canal'.lastIndexOf('a', 0); // returns -1 | ||
+'canal'.lastIndexOf('x'); // returns -1 | ||
+'Blue Whale, Killer Whale'.lastIndexOf('blue'); // returns -1 | ||
+ | ||
+var anyString = 'Brave new world'; | ||
+ | ||
+console.log('The index of the first w from the beginning is ' + anyString.indexOf('w')); | ||
+// logs 8 | ||
+console.log('The index of the first w from the end is ' + anyString.lastIndexOf('w')); | ||
+// logs 10 | ||
+console.log('The index of "new" from the beginning is ' + anyString.indexOf('new')); | ||
+// logs 6 | ||
+console.log('The index of "new" from the end is ' + anyString.lastIndexOf('new')); | ||
+// logs 6 | ||
+``` | ||
+ | ||
+```js | ||
+var str = "time, time"; | ||
+ | ||
+var s = ""; | ||
+s += "time is at position " + str.lastIndexOf("time"); | ||
+s += "<br />"; | ||
+s += "abc is at position " + str.lastIndexOf("abc"); | ||
+ | ||
+document.write(s); | ||
+ | ||
+// Output: | ||
+// time is at position 6 | ||
+// abc is at position -1 | ||
+``` |
49
js-String-prototype-match.md
@@ -0,0 +1,49 @@ | ||
+# js String prototype match | ||
+The `match()` method retrieves the matches when matching a string against a regular expression. | ||
+ | ||
+## Syntax | ||
+```js | ||
+str.match(regexp) | ||
+``` | ||
+ | ||
+### Parameters | ||
+ | ||
+**regexp** | ||
+ | ||
+A regular expression object. If a non-RegExp object obj is passed, it is implicitly converted to a RegExp by using `new RegExp(obj)`. | ||
+ | ||
+[MDN link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) | [MSDN link](https://msdn.microsoft.com/en-us/LIBRary/7df7sf4x%28v=vs.94%29.aspx) | ||
+ | ||
+##Returns | ||
+An `Array` containing the matched results or `null` if there were no matches. | ||
+ | ||
+##Description | ||
+If the regular expression does not include the `g` flag, returns the same result as `RegExp.exec()`. The returned `Array` has an extra input property, which contains the original string that was parsed. In addition, it has an index property, which represents the zero-based index of the match in the string. | ||
+ | ||
+If the regular expression includes the `g` flag, the method returns an `Array` containing all matched substrings rather than match objects. Captured groups are not returned. If there were no matches, the method returns `null`. | ||
+ | ||
+## Examples | ||
+ | ||
+```js | ||
+var str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; | ||
+var regexp = /[A-E]/gi; | ||
+var matches_array = str.match(regexp); | ||
+ | ||
+console.log(matches_array); | ||
+// ['A', 'B', 'C', 'D', 'E', 'a', 'b', 'c', 'd', 'e'] | ||
+``` | ||
+ | ||
+```js | ||
+var str = 'For more information, see Chapter 3.4.5.1'; | ||
+var re = /(chapter \d+(\.\d)*)/i; | ||
+var found = str.match(re); | ||
+ | ||
+console.log(found); | ||
+ | ||
+// logs ['Chapter 3.4.5.1', 'Chapter 3.4.5.1', '.1'] | ||
+ | ||
+// 'Chapter 3.4.5.1' is the first match and the first value | ||
+// remembered from `(Chapter \d+(\.\d)*)`. | ||
+ | ||
+// '.1' is the last value remembered from `(\.\d)`. | ||
+``` |
62
js-String-prototype-replace.md
@@ -0,0 +1,62 @@ | ||
+# js String prototype replace | ||
+The `replace()` method returns a new string with some or all matches of a pattern replaced by a replacement. The pattern can be a string or a `RegExp`, and the replacement can be a string or a function to be called for each match. | ||
+ | ||
+## Syntax | ||
+```js | ||
+str.replace(regexp|substr, newSubStr|function[, flags]) | ||
+``` | ||
+ | ||
+### Parameters | ||
+ | ||
+**regexp (pattern)** | ||
+ | ||
+A RegExp object. The match is replaced by the return value of parameter #2. | ||
+ | ||
+**substr (pattern)** | ||
+ | ||
+A String that is to be replaced by newSubStr. | ||
+ | ||
+**newSubStr (replacement)** | ||
+ | ||
+ The String that replaces the substring received from parameter #1. A number of special replacement patterns are supported; see the "Specifying a string as a parameter" section below. | ||
+ | ||
+**function (replacement)** | ||
+ | ||
+A function to be invoked to create the new substring (to put in place of the substring received from parameter #1). The arguments supplied to this function are described in the "Specifying a function as a parameter" section below. | ||
+ | ||
+[MDN link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) | [MSDN link](https://msdn.microsoft.com/en-us/LIBRary/t0kbytzc%28v=vs.94%29.aspx) | ||
+ | ||
+##Returns | ||
+A new string with some or all matches of a pattern replaced by a replacement. | ||
+ | ||
+##Description | ||
+This method does not change the String object it is called on. It simply returns a new string. | ||
+ | ||
+To perform a global search and replace, either include the g switch in the regular expression or if the first parameter is a string, include g in the flags parameter. | ||
+ | ||
+## Examples | ||
+ | ||
+```js | ||
+var str = 'Twas the night before Xmas...'; | ||
+var newstr = str.replace(/xmas/i, 'Christmas'); | ||
+console.log(newstr); // Twas the night before Christmas... | ||
+``` | ||
+ | ||
+```js | ||
+function f2c(s1) { | ||
+ // Initialize pattern. | ||
+ var test = /(\d+(\.\d*)?)F\b/g; | ||
+ | ||
+ // Use a function for the replacement. | ||
+ var s2 = s1.replace(test, | ||
+ function($0,$1,$2) | ||
+ { | ||
+ return((($1-32) * 5/9) + "C"); | ||
+ } | ||
+ ) | ||
+ return s2; | ||
+} | ||
+document.write(f2c("Water freezes at 32F and boils at 212F.")); | ||
+ | ||
+// Output: Water freezes at 0C and boils at 100C. | ||
+``` |
61
js-String-prototype-substr.md
@@ -0,0 +1,61 @@ | ||
+# js String prototype substr | ||
+Gets a substring beginning at the specified location and having the specified length. | ||
+ | ||
+## Syntax | ||
+```js | ||
+str.substr(start[, length]) | ||
+``` | ||
+ | ||
+### Parameters | ||
+ | ||
+**start** | ||
+ | ||
+Location at which to begin extracting characters. If a negative number is given, it is treated as strLength + start where strLength is the length of the string (for example, if start is -3 it is treated as strLength - 3.) | ||
+ | ||
+**length** | ||
+ | ||
+Optional. The number of characters to extract. | ||
+ | ||
+[MDN link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr) | [MSDN link](https://msdn.microsoft.com/en-us/LIBRary/0esxc5wy%28v=vs.94%29.aspx) | ||
+ | ||
+##Returns | ||
+The characters in a string beginning at the specified location through the specified number of characters. | ||
+ | ||
+##Description | ||
+`start` is a character index. The index of the first character is 0, and the index of the last character is 1 less than the length of the string. `substr()` begins extracting characters at start and collects length characters (unless it reaches the end of the string first, in which case it will return fewer). | ||
+ | ||
+If `start` is positive and is greater than or equal to the length of the string, `substr()` returns an empty string. | ||
+ | ||
+If `start` is negative, `substr()` uses it as a character index from the end of the string. If `start` is negative and `abs(start)` is larger than the length of the string, `substr()` uses 0 as the start index. Note: the described handling of negative values of the start argument is not supported by Microsoft JScript. | ||
+ | ||
+If `length` is 0 or negative, `substr()` returns an empty string. If length is omitted, `substr()` extracts characters to the end of the string. | ||
+ | ||
+## Examples | ||
+ | ||
+```js | ||
+var str = 'abcdefghij'; | ||
+ | ||
+console.log('(1, 2): ' + str.substr(1, 2)); // '(1, 2): bc' | ||
+console.log('(-3, 2): ' + str.substr(-3, 2)); // '(-3, 2): hi' | ||
+console.log('(-3): ' + str.substr(-3)); // '(-3): hij' | ||
+console.log('(1): ' + str.substr(1)); // '(1): bcdefghij' | ||
+console.log('(-20, 2): ' + str.substr(-20, 2)); // '(-20, 2): ab' | ||
+console.log('(20, 2): ' + str.substr(20, 2)); // '(20, 2): ' | ||
+``` | ||
+ | ||
+```js | ||
+var s = "The quick brown fox jumps over the lazy dog."; | ||
+var ss = s.substr(10, 5); | ||
+document.write("[" + ss + "] <br>"); | ||
+ | ||
+ss = s.substr(10); | ||
+document.write("[" + ss + "] <br>"); | ||
+ | ||
+ss = s.substr(10, -5); | ||
+document.write("[" + ss + "] <br>"); | ||
+ | ||
+// Output: | ||
+// [brown] | ||
+// [brown fox jumps over the lazy dog.] | ||
+// [] | ||
+``` |
59
js-String-prototype-substring.md
@@ -0,0 +1,59 @@ | ||
+# js String prototype substring | ||
+The `substring()` method returns a subset of a string between one index and another, or through the end of the string. | ||
+ | ||
+## Syntax | ||
+```js | ||
+str.substring(indexStart[, indexEnd]) | ||
+``` | ||
+ | ||
+### Parameters | ||
+ | ||
+**indexStart** | ||
+ | ||
+An integer between 0 and the length of the string, specifying the offset into the string of the first character to include in the returned substring. | ||
+ | ||
+**indexEnd** | ||
+ | ||
+Optional. An integer between 0 and the length of the string, which specifies the offset into the string of the first character not to include in the returned substring. | ||
+ | ||
+[MDN link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring) | [MSDN link](https://msdn.microsoft.com/en-us/LIBRary/3cz15ahb%28v=vs.94%29.aspx) | ||
+ | ||
+##Description | ||
+`substring()` extracts characters from `indexStart` up to but not including `indexEnd`. In particular: | ||
+ | ||
+- If `indexStart` equals `indexEnd`, `substring()` returns an empty string. | ||
+- If `indexEnd` is omitted, `substring()` extracts characters to the end of the string. | ||
+- If either argument is less than 0 or is `NaN`, it is treated as if it were 0. | ||
+- If either argument is greater than `stringName.length`, it is treated as if it were `stringName.length`. | ||
+ | ||
+If `indexStart` is greater than `indexEnd`, then the effect of `substring()` is as if the two arguments were swapped; for example, `str.substring(1, 0) == str.substring(0, 1)`. | ||
+ | ||
+## Examples | ||
+ | ||
+```js | ||
+var anyString = 'Mozilla'; | ||
+ | ||
+// Displays 'Moz' | ||
+console.log(anyString.substring(0, 3)); | ||
+console.log(anyString.substring(3, 0)); | ||
+ | ||
+// Displays 'lla' | ||
+console.log(anyString.substring(4, 7)); | ||
+console.log(anyString.substring(7, 4)); | ||
+ | ||
+// Displays 'Mozill' | ||
+console.log(anyString.substring(0, 6)); | ||
+ | ||
+// Displays 'Mozilla' | ||
+console.log(anyString.substring(0, 7)); | ||
+console.log(anyString.substring(0, 10)); | ||
+``` | ||
+ | ||
+```js | ||
+var s = "The quick brown fox jumps over the lazy dog."; | ||
+var ss = s.substring(10, 15); | ||
+document.write(ss); | ||
+ | ||
+// Output: | ||
+// brown | ||
+``` |
49
parseInt.md
@@ -0,0 +1,49 @@ | ||
+# parseInt() | ||
+The `parseInt()` function parses a string argument and returns an integer of the specified `radix` (the base in mathematical numeral systems). | ||
+ | ||
+## Syntax | ||
+```js | ||
+parseInt(string, radix); | ||
+``` | ||
+ | ||
+## Parameters | ||
+ | ||
+**string** | ||
+ | ||
+The value to parse. If string is not a string, then it is converted to a string (using the ToString abstract operation). Leading whitespace in the string is ignored. | ||
+ | ||
+**radix** | ||
+ | ||
+An integer between 2 and 36 that represents the radix (the base in mathematical numeral systems) of the above mentioned string. Specify 10 for the decimal numeral system commonly used by humans. Always specify this parameter to eliminate reader confusion and to guarantee predictable behavior. Different implementations produce different results when a radix is not specified, usually defaulting the value to 10. | ||
+ | ||
+[MDN link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt) | [MSDN link](https://msdn.microsoft.com/en-US/library/x53yedee%28v=vs.94%29.aspx) | ||
+ | ||
+##Description | ||
+The parseInt function converts its first argument to a string, parses it, and returns an integer or NaN. If not NaN, the returned value will be the decimal integer representation of the first argument taken as a number in the specified radix (base). For example, a radix of 10 indicates to convert from a decimal number, 8 octal, 16 hexadecimal, and so on. For radices above 10, the letters of the alphabet indicate numerals greater than 9. For example, for hexadecimal numbers (base 16), A through F are used. | ||
+ | ||
+For arithmetic purposes, the `NaN` value is not a number in any radix. You can call the `isNaN` function to determine if the result of `parseInt` is NaN. If `NaN` is passed on to arithmetic operations, the operation results will also be `NaN`. | ||
+ | ||
+To convert number to its string literal in a particular radix use `intValue.toString(radix)`. | ||
+ | ||
+## Examples | ||
+ | ||
+```js | ||
+//The following examples all return 15: | ||
+parseInt(" 0xF", 16); | ||
+parseInt(" F", 16); | ||
+parseInt("17", 8); | ||
+parseInt(021, 8); | ||
+parseInt("015", 10); | ||
+parseInt(15.99, 10); | ||
+parseInt("15,123", 10); | ||
+parseInt("FXX123", 16); | ||
+parseInt("1111", 2); | ||
+parseInt("15*3", 10); | ||
+parseInt("15e2", 10); | ||
+parseInt("15px", 10); | ||
+parseInt("12", 13); | ||
+ | ||
+//The following examples return NaN: | ||
+parseInt("Hello", 8); // Not a number at all | ||
+parseInt("546", 2); // Digits are not valid for binary representations | ||
+``` |
0 comments on commit
9020ff7