1.0.11 • Published 3 years ago

searchobj v1.0.11

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Version Badge Number of Downloads Badge

searchobj-node-module

A module for returning a key's value from a JavaScript object. It traverses the entire object and returns the value associated with the key, whether it's a string, JavaScript object, or array.

For example, with this object as a source:

let test = {
    'info':
    {
      'name': 'Joe Blow',
      'address': '543 Main St',
      'phone_numbers':
      [
        {
          'home': '555-555-4444'
        },
        {
          'work': '555-444-3333'
        }
      ]
    }
  }

searchobj(test, 'address') will return:

543 Main St

...while searchobj(test, 'phone_numbers') will return:

[ { home: '555-555-4444' }, { work: '555-444-3333' } ]

Usage:

const searchobj = require('searchobj')
...
conole.log(searchobj(<object to search>, <key to search for>));

To test, run npm test. You'll see the test object as well as the results of several queries against it.

1.0.11

3 years ago

1.0.10

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago