Looking to get a head start on your next software interview? Pickup a copy of the best book to prepare: Cracking The Coding Interview!
const myTuple = ['apple', 'banana', 'cherry'];
We can access individual values in the tuple using array indexing:
console.log(myTuple); // Output: 'apple'
Just like with Python tuples, we cannot modify the values in the array:
myTuple = 'orange'; // This will throw an error
However, we can still perform operations on the tuple, such as concatenation:
const myOtherTuple = ['date', 'elderberry'];
const concatenatedTuple = myTuple.concat(myOtherTuple);
concatenatedTuple contains all the values from both tuples:
console.log(concatenatedTuple); // Output: ['apple', 'banana', 'cherry', 'date', 'elderberry']