Last active
July 2, 2022 05:29
-
-
Save rizalp/5467463 to your computer and use it in GitHub Desktop.
JavaScript: String
#JavaScript #string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = 9 + "7"; // = "97, string" | |
var b = "7" + 9; // = "79 string" | |
var fooInt = parseInt("34s12", 10); //34 | |
fooInt = parseInt("hello", 10); //NaN | |
var fooFloat = parseFloat("3.14", 10); // 3.14 | |
var words = "Cities of the Interior"; | |
alert(words.split(" ")); //can only do split on string | |
// [Cities,of,the,Interior] | |
words.charAt(0); //C | |
var array = ["a", "b", "c d"]; | |
alert(array.join(" ").split(" ")); //command always start from the back | |
// [a,b,c,d] | |
function startsWith(string, pattern) { | |
return string.slice(0, pattern.length) == pattern; | |
} | |
alert(startsWith("rotation", "rot")); // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment