<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title> <script> //var a = ‘welcome to china‘; //将字符串中的三个单词的首字母转化成大写;返回Welcome To China; var a = ‘welcome to china‘; var b = a.split(‘ ‘);//字符串转化为数组; alert(b); var c = [];//定义一个空数组; for (var i = 0;i < b.length;i++){ c.push(b[i].charAt(0).toUpperCase() + b[i].substring(1));//在空数组的后面添加数组b(第i个)的(第一个)转化为大写加上截取数组b第i个的(从第二个开始到最后); } console.log(c.join(‘ ‘));//弹出c数组并转化为字符串; </script></head><body> </body></html>
原文地址:https://www.cnblogs.com/yxs1530/p/10242399.html
时间: 2024-10-07 06:36:53