-
Notifications
You must be signed in to change notification settings - Fork 0
/
string.js
41 lines (27 loc) · 855 Bytes
/
string.js
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
35
36
37
38
39
40
41
// A string in JavaScript is a sequence of characters, such as letters, numbers, and symbols
console.log("yigtiu")
const str = "Lorem"
console.log(str.length)
console.log(str.charAt(0))
console.log(str[0])
// find ascii value
console.log(str.charCodeAt(0))
console.log(str.includes("l"), str.includes("L"))
console.log(str.indexOf("L"))
console.log(str.lastIndexOf("m"))
const str1 = " Lorem1 Lorem1 "
console.log(str.toLowerCase())
console.log(str.toUpperCase())
console.log(str1.trim())
// check string are equal
console.log(str.localeCompare(str1))
console.log(str.localeCompare(str))
// replace
console.log(str1.replace("Lorem1", "ipsum"))
// get char
console.log(str1.split(""))
console.log(str1.split("").join("."))
const num = 123
console.log(num, num.toString())
console.log(JSON.stringify({ id: 1 }))
console.log(`${str} ${str1}`)