Complete the code to access the first character of the string.
const word = "hello"; const firstChar = word[1];
Strings in TypeScript can be accessed like arrays using square brackets []. So word[0] gives the first character.
Complete the code to find the length of the string.
const text = "data"; const length = text[1];
The length property of a string gives the number of characters. It is accessed without parentheses.
Fix the error in the code to get the last character of the string.
const name = "world"; const lastChar = name[1];
Since string indexes start at 0, the last character is at index length - 1.
Fill both blanks to create a new string with the first and last characters combined.
const word = "string"; const newWord = word[1] + word[2];
The first character is at index 0 and the last character is at index length - 1.
Fill all three blanks to create an object mapping each character to its index if the character is a vowel.
const vowels = ['a', 'e', 'i', 'o', 'u']; const word = "apple"; const vowelIndices = {}; for (let i = 0; i < word.length; i++) { if (vowels[3](word[i])) { vowelIndices[[1]] = [2]; } };
This creates an object where each vowel character in the word is a key, and its index is the value. The includes method checks if the character is a vowel.
