Reputation: 591
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"?
Upvotes: -1
Views: 81
Reputation: 19212
This is what you are looking for:
var myArray = new Array("Red","Blue");
Upvotes: -1
Reputation: 6948
Do you mean splitting string?
var title = "Red, Blue";
var titleArray = title.split(", ");
Upvotes: -1
Reputation: 49372
You can create an array as :
var title = "Red, Blue";
var array = tile.split(',');
OR ,
var array1 = document.getElementById('yourElementID')
.getAttribute('tile').split(',');
Upvotes: 0