JavaScript variable assignments from tuples

前端 未结 13 1358
[愿得一人]
[愿得一人] 2020-12-04 18:26

In other languages like Python 2 and Python 3, you can define and assign values to a tuple variable, and retrieve their values like this:

tuple = (\"Bob\", 2         


        
13条回答
  •  一向
    一向 (楼主)
    2020-12-04 19:03

    This "tuple" feature it is called destructuring in EcmaScript2015 and is soon to be supported by up to date browsers. For the time being, only Firefox and Chrome support it.

    But hey, you can use a transpiler.

    The code would look as nice as python:

    let tuple = ["Bob", 24]
    let [name, age] = tuple
    
    console.log(name)
    console.log(age)
    

提交回复
热议问题