find the first element in an array in typescript

To find the first element in an array in TypeScript, you can simply access its 0th index. Here's an example:

index.ts
const myArray: string[] = ['foo', 'bar', 'baz'];
const firstElement: string = myArray[0];
console.log(firstElement); // Output: 'foo'
134 chars
4 lines

In the above example, we first declare an array of strings and assign it some values. We then declare a constant called firstElement and assign it the value at the 0th index of myArray. Finally, we log the value of firstElement to the console, which should output 'foo'.

gistlibby LogSnag