/

HTML / CSS / JavaScript Tutorial

JavaScript String method: includes()

[this page | pdf | back links]

The includes() method (when applied to a JavaScript string) returns converts Unicode values into characters.

 

It has the following syntax with the following parameters:

 

string.includes(searchstring, start)

 

Parameter

Required / Optional

Description

searchstring

Required

String to be searched for

start

Optional

(Default is 0). Position at which to start search

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table,th,tr,td {border: 1px solid black; border-collapse: collapse;}
</style>
</head>
<body>
<table>
<tr>
<th>Example</th>
<th>Resulting value of <code>x</code></th>
</tr>
<tr>
<td><code id="Example"></code></td>
<td><code id="Result"></code></td>
</tr>
</table>

<script>
var y = "abcde", y2 = "bcd";
document.getElementById("Example").innerHTML =
  'var y = "' + y + '";<br>' +
  'var x = y.includes("' + y2 + '");';
document.getElementById("Result").innerHTML
  = y.includes(y2);
</script>

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedJavaScriptMethodStringIncludes() {
  var z = "abc"; return !!z.includes;
}


NAVIGATION LINKS
Contents | Prev | Next | JavaScript String Variables


Desktop view | Switch to Mobile