관리 메뉴

Silver Library (Archived)

[JS] string includes() method 본문

F2. Problem & Solving/Solving

[JS] string includes() method

Ayin Kim 2021. 7. 6. 13:15
반응형
<!DOCTYPE html>
<html>
    <body>
        <p id="GFG"></p>
        <script>
            var str = "Welcome to GeeksforGeeks.";
            var check = str.includes("Geeks");
            document.getElementById("GFG").innerHTML = check;
        </script>
    </body>
</html>

output : true

 

1. This is an instance to use as a checker from the existing data.

In this case, includes() method belongs to var str.

As 'Geeks' string characters does exist on that var str, the outcome regarding this variable will output : true.

 

Further info:

Syntax:string.includes(searchvalue, start)

Parameters Used:

  • search value: It is the string in which the search will take place.
  • start: This is the position from where the search will be processed
    (although this parameter is not necessary if this is not mentioned
    the search will begin from the start of the string).

Be sure to define or initialise the variable that I plan to use it for. Otherwise, it will return false.

 

For further info: https://www.geeksforgeeks.org/javascript-string-includes-method/

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes

 

Array.prototype.includes() - JavaScript | MDN

The includes() method determines whether an array includes a certain value among its entries, returning true or false as appropriate.

developer.mozilla.org

 

'F2. Problem & Solving > Solving' 카테고리의 다른 글

JS - switch  (0) 2021.07.06
[Node.js] - what is readline() modul?  (0) 2021.07.06
Loops - JS algorithm  (0) 2021.06.12
Conditional statements: switch  (0) 2021.06.12
Conditional statement: if-else  (0) 2021.06.12