Created
January 20, 2020 00:35
-
-
Save prof3ssorSt3v3/54f2b5e7fcad766936f1ac617e3f83fe to your computer and use it in GitHub Desktop.
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
//treating Strings like Arrays | |
let log = console.log; | |
let str = "Ragnar Lothbrok"; | |
// log(str[0], str[1]); | |
// log(str.charAt(0), str.charAt(1)); | |
let arr = str.split(""); | |
let arr2 = Array.from(str); | |
//log(arr, arr2); | |
// log(arr[0], arr2[1]); | |
// concat() - combine two arrays OR combine two strings | |
// str.concat("asdf"); | |
// arr.concat(arr2); | |
// str.indexOf("g") //2 str.lastIndexOf("g") // 3 | |
// arr.indexOf("R"); //0 | |
// str.includes("R") //true arr.includes("R") //true | |
// slice(begin, end) - extract / shallow copy of part of the array or string | |
// str.slice(1, 3) // agn arr.slice(1, 3) . // ["a", "g", "n"] | |
for (let char of str) { | |
log(char); | |
} | |
for (let char of arr) { | |
log(char); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment