Json Function
Search…
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

1
$ npm install json-function
Copied!

Import

1
import { limit } from 'json-function';
Copied!

Usage

Example Data
1
const data = [
2
{
3
id: 1,
4
userId: 1,
5
title: "quis ut nam facilis et officia qui"
6
},
7
{
8
id: 2,
9
userId: 1,
10
title: "lorem ipsum"
11
},
12
{
13
id: 3,
14
userId: 2,
15
title: "delectus aut autem"
16
}
17
];
Copied!
Only Limit Syntax
1
limit(data, 2);
2
// limit([arr, [limit]])
Copied!
Output
1
[
2
{
3
id: 1,
4
userId: 1,
5
title: "quis ut nam facilis et officia qui"
6
},
7
{
8
id: 2,
9
userId: 1,
10
title: "lorem ipsum"
11
}
12
];
Copied!
Limit and Start Syntax
1
limit(data, 2, 1);
2
// limit([arr, [limit, [start]]])
Copied!
Output
1
[
2
{
3
id: 2,
4
userId: 1,
5
title: "lorem ipsum"
6
},
7
{
8
id: 3,
9
userId: 2,
10
title: "delectus aut autem"
11
}
12
];
Copied!
Last modified 2yr ago
Copy link
Contents
Usage