Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save davidystephenson/a253e55369bdfb1e136c9bec0b76c643 to your computer and use it in GitHub Desktop.

Select an option

Save davidystephenson/a253e55369bdfb1e136c9bec0b76c643 to your computer and use it in GitHub Desktop.
<script>
const letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
const characters = ['.', ':', ...letters, ...numbers, '!', '?']
console.log('characters', characters)
const [firstLetter, secondLetter, thirdLetter, ...rest] = letters
// Log the first three letters individually
console.log('firstLetter', firstLetter, 'secondLetter', secondLetter, 'thirdLetter', thirdLetter)
// Log the remaining letters as a single array
console.log(rest)
const vehicleSpeeds = {
bicycle: 10,
mustang: 150,
racecar: 200,
fighter: 2000,
pogo: 2,
starship: 10000000000000,
}
console.log('vehicleSpeeds', vehicleSpeeds)
// const bicycle = vehicleSpeeds.bicycle
// const racecar = vehicleSpeeds.racecar
const { fighter, racecar, bicycle, ...others } = vehicleSpeeds
console.log('others', others)
let myVehicle = 'bicycle'
// const mySpeed = vehicleSpeeds[myVehicle]
const { [myVehicle]: mySpeed } = vehicleSpeeds
console.log('mySpeed', mySpeed)
const animalSpeeds = {
turtle: 1,
human: 28,
falcon: 200,
mustang: 50
}
console.log('animalSpeeds', animalSpeeds)
const speeds = {
human: 10,
...vehicleSpeeds,
...animalSpeeds,
earth: 67000,
}
console.log('speeds', speeds)
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment