A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/gearcase/object-set below:

gearcase/object-set: Sets the value at path of object.

Sets the value at path of object.

$ npm install --save object-set 

For more use-cases see the tests

var set    = require('object-set');
var object = { 'a': [{ 'b': { 'c': 3 } }] };

set(object, 'a[0].b.c', 4);
// => { 'a': [{ 'b': { 'c': 4 } }] }

set({ foo: { bar: 'baz' } }, 'foo.arr[0]', 3);
// => { foo: {bar: 'baz', arr: [3] } }

set({ foo: { bar: 'baz' } }, 'foo.arr[1]', 3);
// => { foo: {bar: 'baz', arr: [, 3] } }

set({ foo: { bar: 'baz' } }, 'foo.obj.key', 3);
// => { foo: {bar: 'baz', obj: { key: 3 } } }

set(null, 'foo.obj.key', 3);
// => null

set({ foo: 1 }, 'foo.obj.key', 3);
// => { foo: 1 }

Use it to functionally create an object:

Array.from('12345')
  .map(parseFloat)
	.reduce((o, n) => set(o, n, n**2), {})
// => { 1: 1, 2: 4, 3: 9, 4: 16, 5: 25 }

Pull requests and stars are highly welcome.

For bugs and feature requests, please create an issue.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4