Skip to content

Adds a default return option

Compare
Choose a tag to compare
@devchris devchris released this 21 May 07:16
· 20 commits to master since this release

If it can't find the value, it will return null by default. However, you can now also pass in a default value of what should be returned if it isn't found.

const world = {
  locations: [{
    europe: 'Bamberg',
  }, {
    usa: 'Indianapolis'
  }]
};
world.dig('locations', 0, 'europe', 'germany', { default: [] });
// => []
world.dig('locations', 0, 'europe', 'germany', { default: 'not found' });
// => 'not found'
world.dig('locations', 0, 'europe', 'germany', { default: '' });
// => ''