count-value-in-array
v1.0.0
Published
count value in array
Downloads
4
Readme
count-value-in-array
count value in array
Table of Contents
Quick start
Install
We support all platforms.
npm
For module bundlers such as Webpack or Browserify.
npm i count-value-in-array
Include with <script>
- Download lib
- Add script to html
<script src="count-value-in-array.js"></script>
CDN
Recommended for learning purposes, you can use the latest version:
<script src="https://cdn.jsdelivr.net/npm/count-value-in-array/dist/lib/count-value-in-array.js"></script>
Recommended for production for avoiding unexpected breakage from newer versions:
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/lib/count-value-in-array.js"></script>
Initialization
ES6
count-value-in-array as an ES6 module.
import countValueInArray from 'count-value-in-array';
const valueQuantity = countValueInArray([1, 2, 3, 1, 1, 1], 1)
Node
count-value-in-array as a Node.js module
const countValueInArray = require('count-value-in-array');
const valueQuantity = countValueInArray([1, 2, 3, 1, 1, 1], 1)
Browser
Exports a global variable called countValueInArray
. Use it like this
Connect to html file <script src="https://cdn.jsdelivr.net/npm/count-value-in-array/dist/lib/count-value-in-array.js" ></script>
<script>
const valueQuantity = countValueInArray([1, 2, 3, 1, 1, 1], 1)
</script>
AMD
count-value-in-array as an AMD module. Use with Require.js, System.js, and so on.
- Download lib
- Connect to your module loader
requirejs(['count-value-in-array'], function(countValueInArray) {
const valueQuantity = countValueInArray([1, 2, 3, 1, 1, 1], 1)
});
Methods
countValueInArray
Count values in array
Params
arrayForCount
- Type:
Array
- Description: array where count value
- Type:
countValue
- Type:
any
- Description: value which count
- Type:
Returns
boolean
Example
const arrayForCount = [1, 2, 3, 1, 1, 1]
countValueInArray(arrayForCount, 1)
// => 4
const arrayForCount = [
{name: 'BMW', age: 2},
{name: 'Audi', age: 3},
{name: 'Porsche', age: 4},
{name: 'BMW', age: 2},
]
countValueInArray(arrayForCount, {name: 'BMW', age: 2})
// => 2
Author
webster6667