文章目录
  1. 1. addKey
    1. 1.1. Usage
    2. 1.2. Install
    3. 1.3. Usage
      1. 1.3.1. License

addKey NPM version NPM monthly downloads NPM total downloads Build Status

Add a new key-value pair for each single item of the array type and filter the children

Usage

Works with arrays.

Install

Install with npm:

1
$ npm install --save addkey

Usage

Works with arrays.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const addKey = require("addkey");
let arr = [
{
id: 1,
name: "亚瑟"
},
{
id: 2,
name: "狄仁杰"
},
{
id: 3,
name: "曹操"
}
];
addKey(arr, { isShow: false }, (v, index, array) => {
index === array.length - 1 ? ((v.name = "铠"), (v.isShow = true)) : "";
});

// log arr =>

/*
[
{ id: 1, name: '亚瑟', isShow: false },
{ id: 2, name: '狄仁杰', isShow: false },
{ id: 3, name: '铠', isShow: true }
]
*/

License

Copyright © 2019, xiaoyueyue.
Released under the MIT License.

文章目录
  1. 1. addKey
    1. 1.1. Usage
    2. 1.2. Install
    3. 1.3. Usage
      1. 1.3.1. License