# array-mid

> Get middle element in an n-element array (either left, right, or both elements if n is odd)

Latest version **1.1.0** (published 2022-02-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install array-mid
pnpm add array-mid
yarn add array-mid
bun add array-mid
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2022-02-06 |
| First published | 2022-01-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Evan Biederstedt |
| Maintainers | evanbiederstedt |
| Keywords | array, utils |

## Links

- npm: https://www.npmjs.com/package/array-mid
- Repository: https://github.com/evanbiederstedt/array-mid
- Homepage: https://github.com/evanbiederstedt/array-mid#readme
- Issues: https://github.com/evanbiederstedt/array-mid/issues
- npm.io page: https://npm.io/package/array-mid

## Recent versions

- 1.1.0 (latest) — 2022-02-06
- 1.0.1 — 2022-02-02
- 1.0.0 — 2022-01-30

## README

[![<evanbiederstedt>](https://circleci.com/gh/evanbiederstedt/array-mid.svg?style=svg)](https://app.circleci.com/pipelines/github/evanbiederstedt/array-mid)
[![NPM version](https://img.shields.io/npm/v/array-mid.svg)](https://www.npmjs.com/package/array-mid)


# array-mid

Get middle element in an N-element array (either left, right, or both elements if N is even)


## Installation

```
npm install array-mid
```


## Usage

```
const mid = require('array-mid');

mid([1, 2, 3, 4, 5]);
//=> [3]

// array with an odd number of elements
let seven = [1, 2, 3, 4, 5, 6, 7];
mid(seven);
//=> [4]
mid(seven, 3, 'left');
//=> [1, 2, 3, 4]
mid(seven, 3, 'right');
//=> [4, 5, 6, 7]

// Error thrown here: mid(seven, 2)
// Cannot return an even number of elements n from position="center" of an odd-lengthed array.


// array with an even number of elements
let six = [1, 2, 3, 4, 5, 6];

// Note: for even-lengthed arrays, mid() returns two elements by default (even with n = 1)
mid(six);  
//=> [3, 4]

mid(six, 3, 'left');
//=> [1, 2, 3]
mid(six, 3, 'right');
//=> [4, 5, 6]

// Error thrown here: mid(six, 3)
// Cannot return an odd number of elements n > 1 from position="center" of an even-lengthed array


```

## Background

Based on [array-first](https://github.com/jonschlinkert/array-first).

---
_Source: https://npm.io/package/array-mid · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
