Select

The "Select" function is a practical method where you only get the desired fields of a json data.

Github repository for your stars.

Usage

Install

$ npm install json-function

Import

import { select } from 'json-function';

Usage

Example Data

const data = [
{
firstname: "John",
lastname: "Doe",
book: {
id: 0,
title: "Book Name"
}
},
{
firstname: "Johnny",
lastname: "Doe",
book: {
id: 1,
title: "Book Name 2"
}
}
];

Single Field Select Syntax

select(data, "firstname");

Output

const data = [
{
firstname: "John",
},
{
firstname: "Johnny",
}
];

Multiple Field Select Syntax

select(data, ["firstname", "lastname"]);

Output

const data = [
{
firstname: "John",
lastname: "Doe",
},
{
firstname: "Johnny",
lastname: "Doe",
}
];