Json Function
Search…
InnerJoin
The "innerJoin" function is used to join two arrays.
Github repository for your stars.

Usage

Install

1
$ npm install json-function
Copied!

Import

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

Usage

Example Data
1
const data = [
2
{
3
id: 1,
4
userId: 1,
5
title: "delectus aut autem",
6
},
7
{
8
id: 2,
9
userId: 2,
10
title: "quis ut nam facilis et officia qui",
11
}
12
];
13
14
const data2 = [
15
{
16
id: 1,
17
firstName: "John"
18
},
19
{
20
id: 2,
21
firstName: "Mike"
22
}
23
];
Copied!
Syntax
1
innerJoin(data, data2, "userId", "id");
2
3
// innerJoin([data, [otherData, [dataField, [otherDataField]]]])
Copied!
Output
1
[
2
{
3
id: 1,
4
userId: 1,
5
title: "delectus aut autem",
6
firstName: "John"
7
},
8
{
9
id: 2,
10
userId: 2,
11
title: "quis ut nam facilis et officia qui",
12
firstName: "Mike"
13
}
14
];
Copied!
If two arrays have the same fields, the fields of the second given array are used.
Last modified 2yr ago
Copy link
Contents
Usage