Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

indexof-property

mattdesl28MITdeprecated1.1.1

deprecated

optimized indexof for a known property

index, of, indexof, find, search, array, list, property, indexOfProperty, index-of

readme

indexof-property

frozen

Compiles an optimized indexof function for a known property.

//let's search for the 'name' property
var indexOf = require('indexof-property')('name')

var list = [
    { name: 'foo', data: 5 },
    { name: 'bar', data: 10 },
    { name: 'beep', data: 0 },
    { name: 'foobar', data: -5 },
    { name: 'beep', data: 20 }
]

// prints 2
console.log( indexOf(list, 'beep') )

// prints -1
console.log( indexOf(list, 'blah') )

// prints 4
console.log( indexOf(list, 'beep', 3) )

The function compiles with bracket notation to support unusual property names, e.g. "border-radius".

Usage

NPM

require('indexof-property')(property)

Compiles a new function that searches for the specified property name. The new function has the signature:

i = indexOf(array, value[, start])

Which searches for the first strictly equal match to value and returns that index, or -1 if none was found. The start index defaults to zero if unspecified.

License

MIT, see LICENSE.md for details.