Skip to content

mattdesl/indexof-property

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

[DEPRECATED] optimized indexof for a known property

Resources

License

Stars

Watchers

Forks

Packages

No packages published