forked from ti17m006/code-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv05-string.js
More file actions
34 lines (29 loc) · 1.07 KB
/
v05-string.js
File metadata and controls
34 lines (29 loc) · 1.07 KB
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
/**
* String Method Additions
*/
// ES5 got a trim method
// ES6 includes includes(), startsWith(), endswith() -> case sensitive
/**
* Template literals - introduced in ES6
* A string is inside if a `` (backtick) pair
* let mytext = `some example text ${variableValue}`;
*/
let message = "Nice and sunny day."
console.log(`1 - ${message.startsWith("Nice")}`); // if so returns true
console.log(`2 - ${message.endsWith(".")}`); // if so returns true
console.log(`3 - ${message.includes("n")}`); // if so returns true
//
console.log(`4 - ${message.startsWith("y")}`); // if so returns false
console.log(`5 - ${message.endsWith("Nice")}`); // if so returns false
console.log(`6 - ${message.includes("w")}`); // if so returns false
//
console.log(`7 - ${message.startsWith("y", 13)}`); // character "y" at position 13
console.log(`8 - ${message.endsWith("y", 18)}`); // character "y" at position 18
console.log(`9 - ${message.includes("n", 6)}`);
//
console.log("my Text\ ".repeat(3));
//
//
let indent = " ".repeat(4);
let indentLevel = 0;
let newIndent = indent.repeat(indentLevel + 1);