Skip to content

Instantly share code, notes, and snippets.

@gunn
Last active December 12, 2018 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gunn/d85440a6aabe9d62c9581e54a0195804 to your computer and use it in GitHub Desktop.
Save gunn/d85440a6aabe9d62c9581e54a0195804 to your computer and use it in GitHub Desktop.
Destructure to array or object
const getVersionDetails = ()=> {
const MAJOR = 1
const MINOR = 2
const PATCH = 6
const array = [MAJOR, MINOR, PATCH]
const object = {MAJOR, MINOR, PATCH}
return Object.assign(array, object)
}
const {MAJOR, MINOR, PATCH} = getVersionDetails()
const [major, minor, patch] = getVersionDetails()
getVersionDetails().join(".") //-> "1.2.6"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment