@abou.bakar/has-item 中文文档教程
Array Has Item
has-item 是一个方便的轻量级库,可帮助确定特定项目/对象是否存在于 Javascript 数组中。
Install
- npm install @abou.bakar/has-item
- yarn add @abou.bakar/has-item
Usage
HasItem(Array, value, key)
Check Given Value Exist Or Not.
import HasItem from "@abou.bakar/has-item";
const array=[
{id:1, name:"John"},
{id:2, name:"Doe"},
{id:3, name:"David"},
{id:4, name:"Orbiqon"},
];
const object1={id:4, name:"Orbiqon"};
const object2={id:1, name:"Orbiqon"};
HasItem(array,object1) // returns true
HasItem(array,object2) // returns false
Check Specific value inside object.
import HasItem from "@abou.bakar/has-item";
const array=[
{id:1, name:"John"},
{id:2, name:"Doe"},
{id:3, name:"David"},
{id:4, name:"Orbiqon"},
];
HasItem(array,"John","name") // returns true
HasItem(array,5,"id") // returns false
Parameter | Description | Required |
---|---|---|
First parameter | First parameter is an array | Required |
Second parameter | Second parameter is the value which will check in array | Required |
Third parameter | Third parameter is the key of a specific object element of array which will check in array | Optional |
Array Has Item
has-item is a handy, lightweight library which helps to find out if a particular item/object exists in a Javascript array or not.
Install
- npm install @abou.bakar/has-item
- yarn add @abou.bakar/has-item
Usage
HasItem(Array, value, key)
Check Given Value Exist Or Not.
import HasItem from "@abou.bakar/has-item";
const array=[
{id:1, name:"John"},
{id:2, name:"Doe"},
{id:3, name:"David"},
{id:4, name:"Orbiqon"},
];
const object1={id:4, name:"Orbiqon"};
const object2={id:1, name:"Orbiqon"};
HasItem(array,object1) // returns true
HasItem(array,object2) // returns false
Check Specific value inside object.
import HasItem from "@abou.bakar/has-item";
const array=[
{id:1, name:"John"},
{id:2, name:"Doe"},
{id:3, name:"David"},
{id:4, name:"Orbiqon"},
];
HasItem(array,"John","name") // returns true
HasItem(array,5,"id") // returns false
Parameter | Description | Required |
---|---|---|
First parameter | First parameter is an array | Required |
Second parameter | Second parameter is the value which will check in array | Required |
Third parameter | Third parameter is the key of a specific object element of array which will check in array | Optional |