const num = ["", "一", "二", "三", "四", "五", "六", "七", "八", "九"]; const unit = ["","十", "百","千"]; const formatNum = (v) => { const arr = v.toString().split("").reverse(); let str = ""; for (let i=arr.length-1;i>=0;i--) { if(arr.length == 2 && i==arr.length - 1 && arr[i] == 1) { str +=unit[i] continue; } str += (num[arr[i]]+unit[i]) } return str; }; console.log(formatNum(4515))
标签:arr,const,汉字,length,str,序号,转为,unit From: https://www.cnblogs.com/panyujun/p/17481048.html