1. 正则表达式应考虑去处“-”,采用/pattern/g,匹配多个
2. str.slice.(start,end)返回值不包括end
function cssStyle2DomStyle(sName) { sName=sName.trim(); let pattern=/[^-]\s*\w+/g; let arr=sName.match(pattern); console.log(arr); // map函数目前貌似只能针对Array,不能针对Set // map函数返回值为每个item处理函数返回值集合构成的数组 // join 参数默认为",",故此处必须指明"" return arr.map(function(item,index){ if (index==0) { return item.toLowerCase(); } else { return item.slice(0,1).toUpperCase()+item.slice(1).toLowerCase(); } }).join(""); }