@extra-array/set-path-update
Version:
Sets value at path in a nested array.
64 lines (48 loc) • 1.92 kB
Markdown
Sets value at path in a nested array.
[:package:](https://www.npmjs.com/package/@extra-array/set-path-update)
[:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array)
[:running:](https://npm.runkit.com/@extra-array/set-path-update)
[:vhs:](https://asciinema.org/a/343816)
[:moon:](https://www.npmjs.com/package/@extra-array/set-path-update.min)
[:scroll:](https://unpkg.com/@extra-array/set-path-update/)
[:newspaper:](https://nodef.github.io/extra-array/)
[:blue_book:](https://github.com/nodef/extra-array/wiki/)
> Alternatives: [set], [set$], [setPath$].<br>
> Similar: [hasPath], [getPath], [setPath$], [removePath$].<br>
> Similar: [get], [set], [remove].
> This is part of package [extra-array].
[extra-array]: https://www.npmjs.com/package/extra-array
<br>
```javascript
array.setPath$(x, p, v);
// x: a nested array (updated)
// p: path
// v: value
// → x
```
```javascript
const array = require("extra-array");
var x = [[2, 4], 6, 8];
array.setPath$(x, [1], 60);
// [ [ 2, 4 ], 60, 8 ]
x;
// [ [ 2, 4 ], 60, 8 ]
array.setPath$(x, [0, 1], 40);
// [ [ 2, 40 ], 60, 8 ]
array.setPath$(x, [0, 1, 2], 100);
// [ [ 2, 40 ], 60, 8 ] (path not present, no effect)
```
<br>
<br>
## References
- [ArrayList.get: Java](https://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html#get(int))
- [_.nth: lodash](https://lodash.com/docs/4.17.15#nth)
- [Array.at: sugarjs](https://sugarjs.com/docs/#/Array/at)
[set]: https://github.com/nodef/extra-array/wiki/set
[set$]: https://github.com/nodef/extra-array/wiki/set$
[setPath$]: https://github.com/nodef/extra-array/wiki/setPath$
[hasPath]: https://github.com/nodef/extra-array/wiki/hasPath
[getPath]: https://github.com/nodef/extra-array/wiki/getPath
[removePath$]: https://github.com/nodef/extra-array/wiki/removePath$
[get]: https://github.com/nodef/extra-array/wiki/get
[remove]: https://github.com/nodef/extra-array/wiki/remove