说明:
例如给定一个字符串:hello new world,最后一个单词为world,输出world的长度5
思路:
转化成数组,利用pop()方法返回最后一项的长度
const string = 'tao hua ying luo fei shen jian'
let arr = string.split(' ') // 转化成数组
console.log(arr) // [ 'tao', 'hua', 'ying', 'luo', 'fei', 'shen','jian']
let arr1 = arr.pop() // 抛出最后一项
console.log('answer', arr1.length); // 4
从最简单的开始,坚持就是胜利!!!