Shift + Enter · ਸਟਾਰਟ / ਰੀਸਟਾਰਟ
ਕੋਡ ਪ੍ਰੋਂਪਟ ਗਾਈਡ ਪੜ੍ਹੋ
- ਪ੍ਰੋਗਰਾਮਿੰਗ ਭਾਸ਼ਾ
- TypeScript
- ਮੁਸ਼ਕਿਲ
- ਮਾਧਿਅਮ
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"]);