1.1.1 • Published 10 years ago

indexof-property v1.1.1

Weekly downloads
17
License
MIT
Repository
github
Last release
10 years ago

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.