# freeCodeCamp Challenge Guide: Copy Array Items Using slice()

**URL:** <https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-copy-array-items-using-slice/301158>\
**Category:** freeCodeCamp Contributors\
**Tags:** guide\
**Created:** [August 3, 2019, 5:43am UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-copy-array-items-using-slice/301158 "2019-08-03T05:43:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![camperbot](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/camperbot/32/18364_2.png) [@camperbot](https://forum.freecodecamp.org/u/camperbot)\
**Post date:** [August 3, 2019, 5:43am UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-copy-array-items-using-slice/301158/1 "2019-08-03T05:43:47Z")

</div>

# [Copy Array Items Using slice()](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-data-structures/copy-array-items-using-slice)

- the `slice()` function must be used to return an array consisting of only `warm` and `sunny`.
- Therefore, two parameters must be passed to the `slice()` function. The first parameter must be the index you would like the substring to start at. The second parameter must be the index at which the substring ends.
- Note: The second parameter will end the substring at that exact index.

## Example:

```javascript
return arr.slice(1, 4);
/* This will return a substring consisting of indexs [1,2,3]
    Note: arr[4] is NOT included. */

```

* * *

## Solutions

> **Solution 1 (Click to Show/Hide)**
>
> ```javascript
> function forecast(arr) {
> // change code below this line
> return arr.slice(2, 4);
> }
> 
> // do not change code below this line
> console.log(
> forecast(["cold", "rainy", "warm", "sunny", "cool", "thunderstorms"])
> );
> 
> ```

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 8, 2025, 3:59pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-copy-array-items-using-slice/301158/2 "2025-01-08T15:59:08Z")

</div>

Closed on January 8, 2025, 3:59pm UTC


