0

I want to create an array with a html element. My main problem is, that i just get a string inside an array but no array.

Example: input is: 1,5,7,3,4 inside an array it look like this: ["1,5,7,3,4"] but i want it like this: [1,5,7,3,4]

I look for a solution made in javascript or better in jquery!

0

2 Answers 2

3

split will convert a string to an array.

var myArray = document.getElementById('myInput').value.split(',');
Sign up to request clarification or add additional context in comments.

Comments

1

Use the split function to convert the string to an array.

For example:

<input type="text" id="myInput">1,5,7,3,4</input>

var myInput = $('#myInput').val();
var arr = myInput.split(','); // [1,5,7,3,4]

2 Comments

I know that, thanks. Quentin wrote the vanilla-style, I thought the jQuery equivalent might be useful.
Ah yes, multiple options is never a bad idea :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.