endswith方法_带有示例JavaScript字符串endsWith()方法

endswith方法

字符串endsWith()方法 (String endsWith() Method)

endsWith() method is a string method in JavaScript, it is used to check whether a string ends with a specified substring or not.

EndsWith()方法是JavaScript中的字符串方法,用于检查字符串是否以指定的子字符串结尾。

It returns true – if string ends with a specified substring, and it returns false – if string does not end with the specified substring.

它返回true -如果有一个指定的子字符串结尾,并返回false -如果字符串不与指定的字符串结束。

Syntax:

句法:

    String.endsWith(substring);

Examples:

例子:

    Input:
    str = "IncludeHelp is made for students.";
    substring = "students."
    //function call
    str.endsWith(substring);
    Output:
    True

    Input:
    str = "IncludeHelp is made for students.";
    substring = "Bye"
    //function call
    str.endsWith(substring);
    Output:
    False

Code:

码:

<html>
<head>
<title>JavaScipt Example</title>
</head>

<body>
<script>
	var str = "IncludeHelp is made for students.";
	
	var substring = "students.";	
	if(str.endsWith(substring)){
		document.write(str + " ends with " + substring + "<br>");
	}
	else{
		document.write(str + " does not end with " + substring + "<br>");
	}

	substring = "Bye";
	if(str.endsWith(substring)){
		document.write(str + " ends with " + substring + "<br>");
	}
	else{
		document.write(str + " does not end with " + substring + "<br>");
	}	
</script>
</body>
</html>

Output

输出量

IncludeHelp is made for students. ends with students.
IncludeHelp is made for students. does not end with Bye


翻译自: https://www.includehelp.com/code-snippets/string-endsWith-method-with-example-in-javascript.aspx

endswith方法

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值