Javascript: slice() Can Take Negative Numbers as Indices
Rating: 4
Example
const animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];
console.log(animals.slice(2, -1));
// expected output: Array ["camel", "duck"]
Related Facts
- 6 NPM: How to Find Out Which Dependencies Can Be Updated [#118] Jun 8, 2022
- 5 Javascript: `Object.assign` Modifies an Object in Place [#22] Nov 25, 2021
- 5 Javascript: Optional Chaining [#50] Dec 6, 2021
- 5 Javascript: There Is a Window Resize Event [#57] Dec 8, 2021
- 4 Javascript: `Promise.race` Returns the First Promise That Finishes [#26] Nov 26, 2021
9 more...
- 4 Javascript: How to Make Custom Errors [#41] Dec 3, 2021
- 3 Typescript: How to Use Optional Chaining on Unknown Types [#51] Dec 6, 2021
- 3 Javascript: Promise.any Returns the First Promise That Fulfills, if Any [#53] Dec 8, 2021
- 3 Javascript: You Can Delete Properties With the delete Keyword [#63] Dec 10, 2021
- 3 Javascript: flatMap [#75] Dec 16, 2021
- 3 Javascript: How to Disable Jest Tests [#86] Dec 21, 2021
- 3 Javascript: Object.seal [#107] Feb 23, 2022
- 3 Javascript: Array.prototype.some() [#169] Aug 2, 2022
- 2 Unobtrusive Javascript [#74] Dec 15, 2021