Discuss / JavaScript / 规范名字输入

规范名字输入

Topic source

function normalize(item) { return newItem = String(item[0]).toUpperCase()+ String(item).substring(1).toLowerCase(); }

arr = ['adam', 'LISA', 'barT']; console.log(arr.map(normalize));

似乎是写错了吧Stirng(item)[0].toUpperCase() 这样写才对,因为item确实可能不是字符串。


  • 1

Reply