Let’s explore how slice() works with Array objects using the following example: const nums = This happens without modifying the original array or string, meaning you essentially get to slice the cake and leave it whole at the same time! Array.slice() example As its name suggests, it takes a slice from the entity it is applied to. The method returns items (from arrays) or characters (from strings) according to the provided indices. The slice() method is a part of both the Array and String prototypes, and can be used with either type of object.
0 Comments
Leave a Reply. |