clickBtn () {
// const arr = Array.from(new Set(this.toLowerCase.split(' '))) // 数组去重 [ES6]
const a = this.toLowerCase.split(' ') // 数组去重2 [ES5]
for (var i = 0; i < a.length; i++) {
for (var j = i + 1; j < a.length; j++) {
if (a[i] === a[j]) {
a.splice(j, 1)
}
}
}
const arrN = a.map(item => {
return item.slice(0, 1).toUpperCase() + item.slice(1) // 字符串首字母大写
})
this.toLowerCase = arrN.join(' ')
},
2021.05.13 数组去重 && 字符串首字母大写【面经】
最新推荐文章于 2024-05-17 13:52:13 发布