1

How do I make a variable equal to every item between 2 items in an array? So it would only make the variable contain the items in the array that are above the place 0 in the list.

An example of what I mean is this: let message = array[1, array.length]

So in an array like this ["dog", "cat", "fish", "snake", "elephant"] if it was to be printed to the console it would print cat, fish, snake and elephant

2

1 Answer 1

1

What you are after is splice() and split(). I have added a demo for you below:

var arr = ["dog", "cat", "fish", "snake", "elephant"];

// Array.splice() will take everything at / after the index you specify
console.log(arr.slice(1)); // ['cat','fish','snake','elephant']

// array.splice will show everything located on or between the index you specify.
console.log(arr.splice(1,3)); // ['cat', 'fish', 'snake']
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.