https://github.com/krishcdbry/npm-indexofkey
Which receives array, (key, value) object pair and returns the index of that particular {key,value} pair in that array and also it is flexible enough to return first index , last index and multlple indexes in the form of array.
https://github.com/krishcdbry/npm-indexofkey
Last synced: 5 months ago
JSON representation
Which receives array, (key, value) object pair and returns the index of that particular {key,value} pair in that array and also it is flexible enough to return first index , last index and multlple indexes in the form of array.
- Host: GitHub
- URL: https://github.com/krishcdbry/npm-indexofkey
- Owner: krishcdbry
- License: mit
- Created: 2016-09-11T10:58:33.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-09-12T23:02:19.000Z (almost 10 years ago)
- Last Synced: 2025-10-04T03:53:49.391Z (8 months ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# npm-indexofkey [](https://www.npmjs.com/package/npm-indexofkey)
Which receives array, (key, value) object pair and returns the index of that particular {key,value} pair in that array and also it is flexible enough to return the first index , last index and also an array of multiple indexes.
## Installation
```bash
npm i npm-indexofkey
```
## Usage
```javascript
var indexOfkey = require('npm-indexofkey');
```
## getIndex(array, {key, value})
Receives the input array, (key, value) object pair and returns the first index of that particular {key,value} pair.
```javascript
var indexOfkey = require('npm-indexofkey')
var inputArray = [{"id":null,"number":7},{"isValid":false,"number":362},{"isValid":true,"count":126},{"isValid":false,"number":10}];
indexOfkey.getIndex(inputArray, {"isValid": false});
// 1
```
## getIndexLast(array, {key, value})
Receives the input array, (key, value) object pair and returns the last index of that particular {key,value} pair.
```javascript
var indexOfkey = require('npm-indexofkey')
var inputArray = [{"id":null,"number":7},{"isValid":false,"number":362},{"isValid":true,"count":126},{"isValid":false,"number":10}];
indexOfkey.getIndexLast(inputArray, {"isValid": false});
// 3
```
## getAll(array, {key, value})
Receives the input array, (key, value) object pair and returns the array of all indexes of that particular {key,value} pair.
```javascript
var indexOfkey = require('npm-indexofkey')
var inputArray = [{"id":null,"number":7},{"isValid":false,"number":362},{"isValid":true,"count":126},{"isValid":false,"number":10}];
indexOfkey.getAll(inputArray, {"isValid": false});
// [1,3]
```
## Demo
Demo @[npm-array-unique](https://tonicdev.com/npm/npm-indexofkey)
| https://tonicdev.com/npm/npm-indexofkey
## Author
Krishcdbry [krishcdbry@gmail.com]
## Licence
MIT @[krishcdbry](krishcdbry.com)