I create a variable from a title attribute tile="Red, Blue". Is there a simple way to make this an array. So the array has 2 values "Red" & "Blue"?
asked Jul 14, 2013 at 6:50
user2238083
5912 gold badges10 silver badges21 bronze badges
-
Does this answer your question? How can I convert a comma-separated string to an array?dumbass– dumbass2024年06月20日 11:50:20 +00:00Commented Jun 20, 2024 at 11:50
3 Answers 3
You can create an array as :
var title = "Red, Blue";
var array = tile.split(',');
OR ,
var array1 = document.getElementById('yourElementID')
.getAttribute('tile').split(',');
answered Jul 14, 2013 at 6:51
AllTooSir
49.5k17 gold badges132 silver badges164 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Do you mean splitting string?
var title = "Red, Blue";
var titleArray = title.split(", ");
answered Jul 14, 2013 at 6:52
Sergio
6,9485 gold badges33 silver badges55 bronze badges
Comments
This is what you are looking for:
var myArray = new Array("Red","Blue");
answered Jul 14, 2013 at 6:56
Brian Ogden
19.3k11 gold badges107 silver badges186 bronze badges
Comments
lang-js