0

I have created a textarea for users to enter numbers separated by a new line. I am using this code to assign all of the numbers into an array

 var arrayOfLines = document.getElementById('myTextArea').value.split('\n');

However when I try to do an alert

alert("First element: " + arrayOfLines[0]);

My output ignores the array and only looks like:

First element:

So I need to know how to output the first element of the array through alert.

4
  • To output an array use console.log(arrayOfLines[0]) not the alert() Commented Sep 29, 2017 at 16:11
  • try to console.log it instead, if the value is undefined or such, it will tell it. In an alert, you can also try with JSON.stringify(value) Commented Sep 29, 2017 at 16:11
  • Are you sure that your input has a value? The only reason I could think for this to happen is if either your input with that ID does not exist or the input doesn't have a value. Also, if any other elements with that same id exist then only the first one is found. Commented Sep 29, 2017 at 16:16
  • See here w3schools.com/code/tryit.asp?filename=FK1W5FVK69S4 Commented Sep 29, 2017 at 16:19

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.