---
title: arrayLast
nav:
  title: Tools
  path: /tools
group:
  title: Utils
toc: content
---

## arrayLast

Demo:

```tsx
/**
 * title: 基础用法
 * description: 取出数组中最后一个元素，若不是数组或数组为空数组，则返回undefined
 */

import React from 'react';
import { arrayLast } from 'aim-tools';

const result1 = arrayLast([1, 2]);
const result2 = arrayLast([1, 2, ,]);
const result3 = arrayLast([]);
const result4 = arrayLast('test');

export default () => (
  <pre>
    <code>
      arrayLast([1, 2]); // {result1}
      <br />
      <br />
      arrayLast([1, 2,,]); // {String(result2)}
      <br />
      <br />
      arrayLast([]); // {String(result3)}
      <br />
      <br />
      arrayLast('test'); // {String(result4)}
    </code>
  </pre>
);
```

### API

```typescript
arrayLast(array: Array<any>);
```

### Params

| 参数  | 说明       | 类型       | 默认值 | 必填 |
| :---- | :--------- | :--------- | :----- | :--- |
| array | 取数的数组 | Array<any> | -      | 是   |

### Returns

| 返回值    | 说明                                                                   |
| :-------- | :--------------------------------------------------------------------- |
| undefined | 传入的数据不是数组，或传入的是空数组，或传入的数组最后一个为 undefined |
| data      | 传入数组的最后一位元素                                                 |
