Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support array push notation in _.set #1315

Closed
DylanPiercey opened this issue Jul 2, 2015 · 2 comments
Closed

Support array push notation in _.set #1315

DylanPiercey opened this issue Jul 2, 2015 · 2 comments

Comments

@DylanPiercey
Copy link

Currently when using set it will support the computed property notation so that I can go

_.set({}, "a[b][c]", 1)
// -> { a: { b: { c: 1 } } }

This works great for turning a urlencoded form's input name into an object however it would be nice if the "push" notation was also valid (currently it does nothing).

By that I mean:

_.set({ a: [1] }, "a[]", 2)
// -> { a: [1, 2] }

// currently -> { a: 2 }

Is this possible? It would be pretty handy.

@jdalton
Copy link
Member

jdalton commented Jul 3, 2015

Hmm, with that the problem of consistent behavior across path types rears its head.
I think we'll continue to punt on this for now.

@jdalton jdalton closed this as completed Jul 3, 2015
@jdalton jdalton added the wontfix label Jul 3, 2015
jasonLaster added a commit to jasonLaster/lodash that referenced this issue Aug 13, 2015
This is a POC implementation for supporting negative
indices. There are several performance regressions and shortcuts.

Negative indices are a common pattern that make it easy for developers
to get the last, 2nd-last, value in an array.

The way the implementation was added, it'd have far reaching
implications.

```js
_.result(['a','b','c'], -3) //=> 'a'
_.get(['a','b','c'], -2) //=> 'b'
_.at(['a','b','c'], -1) //=> ['c']
```

It's also possible to support a path push notation where
`a[-0]` could indicate the array location after the last location. This
was brought up by lodash#1315.

```js
_.set({ a: [1] }, 'a[-0]', 2) //=> { a: [1, 2] }
```

@jridgewell and I paired on this.
@lock
Copy link

lock bot commented Jan 18, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants