count-value-in-array
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

illustration

count-value-in-array

count value in array

npm version

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>

  1. Download lib
  2. 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/count-value-in-array@0.0.0/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.

  1. Download lib
  2. 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
  • countValue
    • Type: any
    • Description: value which count

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

Readme

Keywords

none

Package Sidebar

Install

npm i count-value-in-array

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

27 kB

Total Files

19

Last publish

Collaborators

  • webster6667