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.

Parker
  • 3
  • 5
  • To output an array use `console.log(arrayOfLines[0])` not the `alert()` – Zakaria Acharki Sep 29 '17 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)` – Kaddath Sep 29 '17 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. – JonahAaron Sep 29 '17 at 16:16
  • See here https://www.w3schools.com/code/tryit.asp?filename=FK1W5FVK69S4 – A l w a y s S u n n y Sep 29 '17 at 16:19

0 Answers0