Limit

"Limit" is used to get a limited number of elements from a json data. Almost javascript works like slice() but it is much easier and clearer.

Github repository for your stars.

Usage

Install

$ npm install json-function

Import

import { limit } from 'json-function';

Usage

Example Data

const data = [
  {
    id: 1,
    userId: 1,
    title: "quis ut nam facilis et officia qui"
  },
  {
    id: 2,
    userId: 1,
    title: "lorem ipsum"
  },
  {
    id: 3,
    userId: 2,
    title: "delectus aut autem"
  }
];

Only Limit Syntax

limit(data, 2);
// limit([arr, [limit]])

Output

[
  {
    id: 1,
    userId: 1,
    title: "quis ut nam facilis et officia qui"
  },
  {
    id: 2,
    userId: 1,
    title: "lorem ipsum"
  }
];

Limit and Start Syntax

limit(data, 2, 1);
// limit([arr, [limit, [start]]])

Output

[
  {
    id: 2,
    userId: 1,
    title: "lorem ipsum"
  },
  {
    id: 3,
    userId: 2,
    title: "delectus aut autem"
  }
];

Last updated