InnerJoin

The "innerJoin" function is used to join two arrays.

Github repository for your stars.

Usage

Install

$ npm install json-function

Import

import { innerJoin } from 'json-function';

Usage

Example Data

const data = [
{
id: 1,
userId: 1,
title: "delectus aut autem",
},
{
id: 2,
userId: 2,
title: "quis ut nam facilis et officia qui",
}
];
const data2 = [
{
id: 1,
firstName: "John"
},
{
id: 2,
firstName: "Mike"
}
];

Syntax

innerJoin(data, data2, "userId", "id");
// innerJoin([data, [otherData, [dataField, [otherDataField]]]])

Output

[
{
id: 1,
userId: 1,
title: "delectus aut autem",
firstName: "John"
},
{
id: 2,
userId: 2,
title: "quis ut nam facilis et officia qui",
firstName: "Mike"
}
];

If two arrays have the same fields, the fields of the second given array are used.