0

So say I have an array and the user can add do it by a input html tag:

var example=["a","b"];
var command=document.getElementByID("id");

so idk how long the array will be when i execute the next step,which is selecting the last item in the array and register it in an object

example.split(",")
someObject[//how do i chose the last item?]
4
  • 1
    arr.slice().pop() Commented Aug 8, 2016 at 19:45
  • someObject[someObject.length - 1]; Commented Aug 8, 2016 at 19:46
  • arr[arr.length - 1] Commented Aug 8, 2016 at 19:46
  • 3
    @Daniel_L Oh what a wasteful thing to do. Commented Aug 8, 2016 at 19:48

1 Answer 1

1

You can select the last item in a javascript array like this

arr = example.split(",");
lastArr = arr[arr.length - 1];
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.