String variable in the javascript

technical talkiess
0

 String variable in the javascript:-

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>String function in javascript</title>

<script>

    var str = "This is the vishal";

    // first occurance of index agar apko find karna hai  string me kuch to

    var position = str.indexOf("vishal");

    // last occurance of index agar apko find karna hai  string me kuch to

    position = str.lastIndexOf("is");

    console.log(position)

    // 1 se 7 tak slice kar denga string ko

    // var sli = str.slice(1,7)

    // var sli = str.substring(1,9)

    var sli = str.substr(1,3)

    console.log(sli)

    // agar apko string se kuch ko remove karna hai to

    var newString = str.replace("vishal","Test")

    console.log(str)

    console.log(newString)

    console.log(newString)

    // string ko upper case karna hai to use kare

    console.log(str.toUpperCase())

    // string ko small case me karna hai to use kare

    console.log(str.toLowerCase())

    var con_string = str.concat(" Testing buddy                                             ")

    console.log(con_string)

    // trim the string white space

    console.log(con_string.trim())

    // string me character ko search karna hai to

    var char2  = str.charAt(2)

    // character code ko return karta hai

    // char2 = str.charCodeAt(2)

    console.log(char2)

</script>

</head>

<body>

    <div class="container">


    </div>

</body>

</html>
Tags

Post a Comment

0Comments

Thanks you for commenting your questions. I will see question and respond you.

Post a Comment (0)