Reputation: 1065
I want to pop array element, split it and save into different array. say I have two array
arr1 = ["a:b", "c:d"]
arr2 = []
I want to have arr2 as
arr2 = ["a", "b", "c", "d"]
I tried
var arr1 = ["a:b", "c:d"]
var arr2 = [];
var tempdata;
for (var i = 0; i < arr1.length; i++) {
tempdata = arr1.pop();
arr2.merge(tempdata.split(':'));
}
but firebug gives me an error saying merge is not a function.
I also tried
var arr1 = ["a:b", "c:d"]
var arr2 = [];
var tempdata;
for (var i = 0; i < arr1.length; i++) {
tempdata = arr1.pop();
var temparray = [];
temparray = tempdata.split(':');
arr2.merge(temparray);
}
still no luck.
Thanks for the help. PS:I don't mind using Jquery.
Upvotes: 1
Views: 454
Reputation: 342
try converting the first array to string then convert it back to array just like this
var trainindIdArray = traingIds.split(',');
$.each(trainindIdArray, function(index, value) {
alert(index + ': ' + value); // alerts 0:[1 , and 1:2]
});
from Javascript/Jquery Convert string to array question...
happy coding..:D
Upvotes: 0