1.2.0 • Published 3 years ago

@abou.bakar/has-item v1.2.0

Weekly downloads
12
License
MIT
Repository
github
Last release
3 years ago

Array Has Item

Build Status

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
ParameterDescriptionRequired
First parameterFirst parameter is an arrayRequired
Second parameterSecond parameter is the value which will check in arrayRequired
Third parameterThird parameter is the key of a specific object element of array which will check in arrayOptional