Shift + Enter · Bắt đầu / bắt đầu lại
Đọc hướng dẫn đoạn mã
- Ngôn ngữ lập trình
- TypeScript
- Độ khó
- Trung bình
Return the first element while preserving its type.
function firstItem<T>(items: T[]): T | undefined {
return items[0];
}
const firstNumber = firstItem([4, 8, 15]);
const firstName = firstItem(["Ada", "Lin"]);