Javascript/Jquery Convert string to array

Viewed 165894

i have a string

var traingIds = "${triningIdArray}";  // ${triningIdArray} this value getting from server 
alert(traingIds)  // alerts [1,2]
var type = typeof(traingIds ) 
alert(type)   // // alerts String

now i want to convert this to array so that i can iterate

i tried

var trainindIdArray = traingIds.split(',');
$.each(trainindIdArray, function(index, value) { 
    alert(index + ': ' + value);   // alerts 0:[1 ,  and  1:2]
});

how to resolve this?

4 Answers
Related