Created
June 17, 2015 09:46
-
-
Save afonsomatos/b6841476f0ecf12a9135 to your computer and use it in GitHub Desktop.
Most important String features in ES6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If strings starts with substr | |
'myString'.startsWith('my', 0 /* start searching */); // true | |
// If string ends with substr | |
'myString'.endsWith('ring', 8 /* end searching */); // true | |
// If strings has another substr | |
'myString'.includes('str', 0 /* start searching */); // true | |
// Multiply string | |
'woof '.repeat(5); | |
// -- Template strings | |
// String interpolation | |
`504 * 389127 is ${ 504 * 389127}`; | |
// Multiple lines | |
`this is a string | |
very cool` | |
// Raw string prefix | |
String.raw`\n\n`; // \\n\\n | |
// Strings are iterable | |
for (let ch of 'abc'); // a.. b.. c.. | |
// Spread string | |
[...'abc']; // ['a', 'b', 'c'] | |
// Reverse strings | |
[...'eval'].reverse().join(''); // 'lave' | |
// -- Unicode and code points | |
String.fromCodePoint(...codePoints : number[]) : string | |
String.prototype.codePointAt(pos) : number | |
String.prototype.normalize(form? : string) : string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment