已知字符串msg='get-element-by-id';,写一个函数将其转化成驼峰表示法:'getElementById'

xiaoxiao2021-02-28  107

//已知字符串msg='get-element-by-id';,写一个函数将其转化成驼峰表示法:'getElementById'

combo("get-element-by-id");

function combo(msg){

var arr=msg.split("-"); var i=1; for(;i<arr.length;i++){ arr[i]=arr[i].charAt(0).toUpperCase() + arr[i].substr(1,arr[i].length); } console.log(arr);//['get','Element','By','Id'] msg=arr.join(""); console.log(msg)//getElementById }
转载请注明原文地址: https://www.6miu.com/read-22240.html

最新回复(0)