![](https://i.imgur.com/56C2ubQ.png =200x) # Coaching - JavaScript Methods 1 with Founders and Coders --- JavaScript Methods act like functions built into JavaScript. ---- Methods give us the ability to do complex things with relatively little code. --- ## String Methods ---- String methods allow us to modify strings. ---- ### Examples ---- The `charAt()` method tells us which character is at a certain position in a string. ---- ```javascript= let myString = "Antelope" let myCharacter = myString.charAt(3) console.log(myCharacter) ``` ---- The `includes()` method tells us whether a string contains a specified string. ---- ```javascript= let myString = "Anteater" console.log(myString.includes("ant")) console.log(myString.includes("eat")) ``` Note that the includes method is case sensitive. ---- The `split()` method splits a string into an array of substrings. ---- ```javascript= let myString = "The quick brown fox" let characters = myString.split("") let words = myString.split(" ") let parts = myString.split("brown") ``` --- ## Array Methods ---- Array methods allow us to manipulate and alter arrays. ---- ### Examples ---- The `join()` method allows us to join together the values in an array. ---- ```javascript= let myArray = ['l', 'i', 'o', 'n'] let myString = myArray.join(); let myLetters = myArray.join("-") console.log(myString) console.log(myLetters) ``` ---- The `pop()` method removes and returns the last element of an array. ---- ```javascript= let myArray = ['Koala', 'Panda', 'Owl']; let wiseAnimal = myArray.pop(); console.log(wiseAnimal) ``` ---- The `concat()` method allows us to join together two arrays. ---- ```javascript= let firstArray = ['Badger', 'Lemur', 'Leopard']; let secondArray = ['Chimpanzee', 'Wolf']; let joinedArray = firstArray.concat(secondArray) ``` ---- This method can accept any number of arrays as arguments, and can accept strings! ---- The `slice()` method slices out a piece of an array into a new array. ---- ```javascript= let myArray = ['Aardvark', 'Rhino', 'Eagle', 'Bee', 'Earthworm', 'Ant']; let bugs = myArray.slice(3); ``` ---- We can pass two arguments to slice: a start position and an end position. ---- ```javascript= let myArray = ['Aardvark', 'Rhino', 'Eagle', 'Bee', 'Earthworm', 'Ant']; let bugs = myArray.slice(3); let flyingAnimals = myArray.slice(2,4) ``` ----
{"metaMigratedAt":"2023-06-15T20:40:04.051Z","metaMigratedFrom":"YAML","title":"Coaching - JavaScript Methods 1","breaks":true,"slideOptions":"{\"theme\":\"white\"}","contributors":"[{\"id\":\"2967aacf-1990-431e-b963-91e79ce4a2bf\",\"add\":3699,\"del\":1240}]"}
    214 views
   Owned this note