带示例JavaScript大写教程

JavaScript programming language provides functions in order to change the case of the given string, word or sentence. toUpperCase() is the main function that can be used to make the given string, word and sentence completely uppercase.

JavaScript编程语言提供了一些功能,以更改给定字符串,单词或句子的大小写。 toUpperCase()是主要函数,可用于使给定的字符串,单词和句子完全大写。

toUpperCase()函数语法 (toUpperCase() Function Syntax)

toUpperCase() function is provided by a JavaScript string object where it can be called with this object directly. toUpperCase() function does not require any parameter as it will use the object value as a parameter to capitalize.

JavaScript字符串对象提供了toUpperCase()函数,可在其中直接用此对象调用它。 toUpperCase()函数不需要任何参数,因为它将使用对象值作为大写的参数。

OBJECT.toUpperCase()
  • `OBJECT` is the string value we want to make uppercase. This value can be a letter, word, sentence simply a string data type.

    “ OBJECT”是我们要大写的字符串值。 该值可以是字母,单词,句子,也可以是字符串数据类型。
  • `toUpperCase()` is the function we will use to make the OBJECT value uppercase. This function will return the upper

    toUpperCase()是我们用来使OBJECT值大写的函数。 该函数将返回上层

toUpperCase()示例(toUpperCase() Examples)

toUpperCase() function is related to the string object and can be called from a string variable or string literal like below. In this following example, we will create a string variable named sitename and call the toUpperCase() function and assign the returned value into the sitename_uppercase variable. We will also create a string literal with “poftut.com”  and then call the toUpperCase() function from that string literal which will return the uppercase “POFTUT.COM”.

toUpperCase()函数与字符串对象有关,可以从字符串变量或字符串文字中调用,如下所示。 在下面的示例中,我们将创建一个名为sitename的字符串变量,并调用toUpperCase()函数,并将返回的值分配给sitename_uppercase变量。 我们还将使用“ poftut.com”创建一个字符串文字,然后从该字符串文字中调用toUpperCase()函数,该函数将返回大写字母“ POFTUT.COM”。

sitename="poftut.com";
//Prints "poftut.com"
sitename_uppercase=sitename.toUpperCase();
//Prints "POFTUT.COM"
console.log(sitename_uppercase);
//Prints "POFTUT.COM"

console.log(sitename);
//Prints "poftut.com"

"poftut.com".toUpperCase();
//"POFTUT.COM"

a="poftut.com".toUpperCase();
//Prints "POFTUT.COM"
toUpperCase() Examples
toUpperCase() Examples
toUpperCase()示例

大写仅单词的第一个字母(UpperCase Only First Letter Of The Word)

We can also make the first letter of the given word or string uppercase. We will use the charAt() function in order to specify the first letter which index is 0 and then we will use slice() function which will return the remaining string apart from the first letter. In the following example, we will make the string “poftut.com”  first letter uppercase which will look like “Poftut.com”.

我们还可以将给定单词或字符串的首字母大写。 我们将使用charAt()函数来指定索引为0的第一个字母,然后使用slice()函数将返回除第一个字母之外的其余字符串。 在下面的示例中,我们将字符串“ poftut.com”的首字母大写,使其看起来像“ Poftut.com”。

sitename="poftut.com";

sitename_uppercase=sitename.charAt(0).toUpperCase()+sitename.slice(1);
//Prints "Poftut.com"
 

翻译自: https://www.poftut.com/javascript-uppercase-tutorial-with-examples/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值