has-match
v2.0.0
Published
Check object value for match
Downloads
91
Readme
has-match
Check object value for match
Install
npm install has-match
Usage
import hasMatch from 'has-match'
const garden = {
name: 'Sunny Fields',
plants: ['roses', 'lilies', 'gerberas'],
}
hasMatch(garden, 'gerb')
// => true
hasMatch(garden, 'sunny fields')
// => true
hasMatch(garden, 'sunny fields', ['plants'])
// => false
Filter
const gardens = [
{
name: 'Sunny Fields',
plants: ['roses', 'lilies', 'gerberas'],
},
{
name: 'Moony Meadows',
plants: ['cosmos', 'lilies', 'mushrooms'],
},
]
gardens.filter((garden) => hasMatch(garden, 'cosmos'))
// => [{ name: 'Moony Meadows', plants: ['cosmos', 'lilies', 'mushrooms'] }]