• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Miscellaneous / Destructing variable assignment

Destructing variable assignment

Destructing variable assignment

Assigning variables from an array one-by-one is time consuming and silly. Just use destructuring assignment to accomplish this quicker and easier:

let profile = ['bob', 34, 'carpenter'];
let [name, age, job] = profile;
console.log(name);
--> 'bob'

Source

https://levelup.gitconnected.com/6-javascript-code-snippets-for-solving-common-problems-33deb6cacef3

Miscellaneous

Related Snippets:

  • Drop list elements from the right
  • Short-Circuit Evaluation Using &&
  • Get unique values in an array
  • Sorting Objects with a Primary and Secondary Property

Primary Sidebar

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2025 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers