February 2019
Beginner
694 pages
18h 4m
English
As tuples use the array syntax, they can be destructured, or disassembled, in two ways. The first is by means of simple array syntax as follows:
console.log(`tupleType[0] : ${tupleType[0]}`);
console.log(`tupleType[1] : ${tupleType[1]}`);
Here, we are simply logging each property of the tupleType variable to the console by referencing its index within the array, that is, tupleType[0] and typleType[1]. The output of this code would be as follows:
tupleType[0] : test tupleType[1] : false
So we have now created a tuple with a string and boolean value, and destructured it with array syntax. Note that because we are using array syntax, we are able to interrogate the third property of this tuple as follows:
console.log(`tupleType[2] ...
Read now
Unlock full access