// change the string to number const strnum = "10"; console.log(parseInt(strnum)) // change number to string var b = 20; console.log(b.toString()) // convert decimal to a whole numbe var integer = 89.7920; console.log(integer.toFixed()) // you can choose a number postion which you can rounded off var integer = 89.7920; console.log(integer.toFixed(1)) // string inside the double string, use backslash var doubleString = "this stirng \"inside\"the double string" console.log(doubleString) doubleString = this stirng "inside"the double string // length of the string including spaces var myFirstString = "This is my first string" console.log(myFirstString.length) // finding the specific number postion of a letter or word, number start from 0 var myFirstString = "This is my first string" console.log(myFirstString.indexOf("my")) // use this lastIndexOf if there are same word in a string like "This" and "is", only if you want the last index else, use indexOf() var myFirstString = "This is my first string" console.log(myFirstString.lastIndexOf("is")) // get the specifc word just put the first and last index of the word inside the () var myFirstString = "This is my first string" console.log(myFirstString.slice(0, 5)) = This var myFirstString = "This is my first string" console.log(myFirstString.slice(10, 23)) = first string // extract a string from a string, number start from 0 var myFirstString = "This is my first string" console.log(myFirstString.substring(0, 7)) = this is
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter