Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How To Create Javascript Array From Single HTML Input?

<input type="text" id="blah" value="'a1','a2'">
<script>
dd=document.getElementById('blah').value

cars = [dd]
console.log(cars)
</script>

When I try to do it in console I see the result:
[‘"a1", "a2"’]
This is why I can’t use it as array.
What I want is:
["a1","a2"]
I want to use it as array. How can I do it? Is it possible?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<input type="text" id="blah" value="'a1','a2'">
<script>
dd=document.getElementById('blah').value

cars = dd.split(',').map(e=>e.substr(1, e.length-2));
console.log(cars)
</script>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading