Like Array, but Tuple can store a collection of values of varied types:
Syntax
var tuple_name = [value1,value2,value3,…,valuen]
Example:
var my_tuple1 = [0,"one",2,3] var my_tuple2 = [] my_tuple2 = [0,"one",2,3]
Accessing values in Tuples
Syntax
tuple_name[index]
Example:
var my_tuple1 = [0,"one",2,3] console.log(my_tuple1[1])
Result:
[LOG]: one
Destructuring a Tuple
Example:
var my_tuple1 = [0,"one",2,3] var [value1,value2] = my_tuple1 console.log(value1,value2)
Result:
[LOG]: 0, one
Tuple Properties:
length
– return number of items
Tuple Methods:
Like Array