---
title: "Get First or Last N Elements"
description: "Retrieve the first or last `n` elements of an array in TypeScript."
date: "2025-10-02"
tags: ["typescript","array","elements","frontend"]
canonical: "/snippets/typescript/array/get-n-first-or-last"
---

import { Code } from '@astrojs/starlight/components'
import Source from './get-n-first-or-last.ts?raw'

## Get First or Last N Elements

<Code code={Source} lang="ts" title="get-n-first-or-last.ts" wrap />
