Created
April 2, 2016 13:54
-
-
Save goodbedford/12e5d9e49ac7fe6e73d0ec9fba29a45a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// splice( starting-index, delete-count, new-item) | |
// start is index exact, delete-count is how many elements to remove including start | |
// new-item is optional and is added at starting-index | |
// splice is permenant | |
var dogs = ["Pit Bull", " American Cocker Spaniel", "Beagle", " Belgian Malinois"]; | |
var newDog = "Bloodhound"; | |
var guideDog = "Brussels Griffon" | |
// take out Beagle | |
dogs.splice(2,1); | |
console.log("dogs - beagle:", dogs); | |
//add newDog after Pit Bull | |
dogs.splice(1,0,newDog); | |
console.log("newDog after Pit Bull:", dogs); | |
// change one out swap dogs | |
// swap guideDog for Pit Bull | |
dogs.splice(0,1,guideDog); | |
console.log("dogs swap guideDog for Pit Bull:", dogs); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment