Json Function
  • Json Function
  • Changelog
  • Functions
    • Schema
    • InnerJoin
    • Where
    • Select
    • Search
    • OrderBy
    • Limit
    • ToArray
    • Transform
Powered by GitBook
On this page

Was this helpful?

  1. Functions

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.

PreviousOrderByNextToArray

Last updated 6 years ago

Was this helpful?

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"
  }
];
Github