字符串转小驼峰
2023-06-16 10:28:46
ts
const str = 'background-image'
function toLower(s) {
const result = s.split('-')
let res = ''
console.log(result)
result.map((item, index) => {
if (index > 0) {
item.split('').map((it, idx) => {
if (idx > 0) {
res += it
} else {
res += it.toLocaleUpperCase()
}
})
} else {
res += item
}
})
return res
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21