-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4.stringMethods.js
More file actions
24 lines (21 loc) · 1003 Bytes
/
Copy path4.stringMethods.js
File metadata and controls
24 lines (21 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const str1 = 'My dog is "Haru"'
const str2 = "My dog is 'Haru'"
const str3 = "It's my dog!"
const str = 'Apple,Banana,Kiwi'
const start = 6 // Starting from zero
const end = 12 // Non-inclusive end
console.log(str.length) // Prints 17
console.log(str.indexOf('Banana')) // Prints 6
console.log(str.indexOf('Orange')) // Prints -1
console.log(str.slice(start, end)) // Prints Banana
console.log(str.slice(start)) // Prints Banana,Kiwi
console.log(str.charAt(6)) // Prints B
console.log(str[0]) // Prints A
console.log(str.split(',')) // Prints ['Apple', 'Banana', 'Kiwi']
console.log(str.replace('Kiwi','Orange')) // Prints Apple,Banana,Orange
const firstName = 'John'
const lastName = 'Doe'
// Using the concat operator +
console.log('Welcome ' + firstName + ', ' + lastName + '!')
// Using string interpolation (preferred)
console.log(`Welcome ${firstName}, ${lastName}!`)