Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JavaScript: String #JavaScript #string
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
You can’t perform that action at this time.