Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
162
rated 0 times [  169] [ 7]  / answers: 1 / hits: 178270  / 12 Years ago, thu, august 2, 2012, 12:00:00

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?


More From » jquery

 Answers
5

Assuming, as seems to be the case, ${triningIdArray} is a server-side placeholder that is replaced with JS array-literal syntax, just lose the quotes. So:



var traingIds = ${triningIdArray};


not



var traingIds = ${triningIdArray};

[#83904] Wednesday, August 1, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eliezerc

Total Points: 286
Total Questions: 102
Total Answers: 102

Location: Federated States of Micronesia
Member since Sun, May 16, 2021
3 Years ago
;