Angularjs split array
up vote
0
down vote
favorite
I have an array that looks like this
$scope.A = [
[ "1.31069258855609,103.848649478524", "1.31138534529796,103.848923050526" ],
[ "1.31213221536436,103.848328363879", "1.31288473199114,103.849575392632" ]
];
I want to make it into something like this
$scope.B = [
[
[1.31069258855609,103.848649478524], [1.31138534529796,103.848923050526]
],
[
[1.31213221536436,103.848328363879], [1.31288473199114,103.849575392632]
]
];
PS: Sorry if this isnt splitting, I am not sure how to address this problem as
Code:
var latlngs = $scope.polyLineCord.map(subarr => subarr.map(str => str.split(',').map(Number)))
console.log(latlngs)

javascript angularjs
New contributor
ITnyp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
I have an array that looks like this
$scope.A = [
[ "1.31069258855609,103.848649478524", "1.31138534529796,103.848923050526" ],
[ "1.31213221536436,103.848328363879", "1.31288473199114,103.849575392632" ]
];
I want to make it into something like this
$scope.B = [
[
[1.31069258855609,103.848649478524], [1.31138534529796,103.848923050526]
],
[
[1.31213221536436,103.848328363879], [1.31288473199114,103.849575392632]
]
];
PS: Sorry if this isnt splitting, I am not sure how to address this problem as
Code:
var latlngs = $scope.polyLineCord.map(subarr => subarr.map(str => str.split(',').map(Number)))
console.log(latlngs)

javascript angularjs
New contributor
ITnyp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Fetched from an api
– ITnyp
Nov 8 at 9:16
I am trying to plot a polyline in my map
– ITnyp
Nov 8 at 9:17
Ohh, sorry it was a typo edited it
– ITnyp
Nov 8 at 9:18
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have an array that looks like this
$scope.A = [
[ "1.31069258855609,103.848649478524", "1.31138534529796,103.848923050526" ],
[ "1.31213221536436,103.848328363879", "1.31288473199114,103.849575392632" ]
];
I want to make it into something like this
$scope.B = [
[
[1.31069258855609,103.848649478524], [1.31138534529796,103.848923050526]
],
[
[1.31213221536436,103.848328363879], [1.31288473199114,103.849575392632]
]
];
PS: Sorry if this isnt splitting, I am not sure how to address this problem as
Code:
var latlngs = $scope.polyLineCord.map(subarr => subarr.map(str => str.split(',').map(Number)))
console.log(latlngs)

javascript angularjs
New contributor
ITnyp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I have an array that looks like this
$scope.A = [
[ "1.31069258855609,103.848649478524", "1.31138534529796,103.848923050526" ],
[ "1.31213221536436,103.848328363879", "1.31288473199114,103.849575392632" ]
];
I want to make it into something like this
$scope.B = [
[
[1.31069258855609,103.848649478524], [1.31138534529796,103.848923050526]
],
[
[1.31213221536436,103.848328363879], [1.31288473199114,103.849575392632]
]
];
PS: Sorry if this isnt splitting, I am not sure how to address this problem as
Code:
var latlngs = $scope.polyLineCord.map(subarr => subarr.map(str => str.split(',').map(Number)))
console.log(latlngs)

javascript angularjs
javascript angularjs
New contributor
ITnyp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
ITnyp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited Nov 8 at 9:36
New contributor
ITnyp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Nov 8 at 9:15
ITnyp
205
205
New contributor
ITnyp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
ITnyp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
ITnyp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Fetched from an api
– ITnyp
Nov 8 at 9:16
I am trying to plot a polyline in my map
– ITnyp
Nov 8 at 9:17
Ohh, sorry it was a typo edited it
– ITnyp
Nov 8 at 9:18
add a comment |
Fetched from an api
– ITnyp
Nov 8 at 9:16
I am trying to plot a polyline in my map
– ITnyp
Nov 8 at 9:17
Ohh, sorry it was a typo edited it
– ITnyp
Nov 8 at 9:18
Fetched from an api
– ITnyp
Nov 8 at 9:16
Fetched from an api
– ITnyp
Nov 8 at 9:16
I am trying to plot a polyline in my map
– ITnyp
Nov 8 at 9:17
I am trying to plot a polyline in my map
– ITnyp
Nov 8 at 9:17
Ohh, sorry it was a typo edited it
– ITnyp
Nov 8 at 9:18
Ohh, sorry it was a typo edited it
– ITnyp
Nov 8 at 9:18
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
map each item in the outer array, then .map each subarray and split by commas, and map again by Number to transform the strings to numbers:
const input = [
["1.31069258855609,103.848649478524", "1.31138534529796,103.848923050526"],
["1.31213221536436,103.848328363879", "1.31288473199114,103.849575392632"]
];
console.log(
input.map(
subarr => subarr.map(
str => str.split(',').map(Number)
)
)
);
I have no idea how to read this, is it possible to store the result into a variable?
– ITnyp
Nov 8 at 9:21
Just put something likevar somevar =in place ofconsole.log(, theconsole.login the code above is just to demonstrate that it results in the output you want
– CertainPerformance
Nov 8 at 9:23
Nice! Exactly how i want it. Thanks again for the help!
– ITnyp
Nov 8 at 9:25
are you still there? I don't know why but I am return with a different result when I use it on my code
– ITnyp
Nov 8 at 9:35
The result I am returned is nested in an array
– ITnyp
Nov 8 at 9:37
|
show 3 more comments
up vote
0
down vote
A function to do the job:
function splitMyArray(arr) {
for (var i = 0; i < arr.length; ++i) {
var line = arr[i];
for (var k = 0; k < line.length; ++k) {
var parts = line[k].split(',');
line[k] = [parseFloat(parts[0]), parseFloat(parts[1])];
}
}
return arr;
}
Usage example:
var myArr = [
["1.31,103.84", "1.32,103.85"],
["1.39,103.77", "1.40,103.78"]
];
var splitted = splitMyArray(myArr);
console.log(splitted);
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
map each item in the outer array, then .map each subarray and split by commas, and map again by Number to transform the strings to numbers:
const input = [
["1.31069258855609,103.848649478524", "1.31138534529796,103.848923050526"],
["1.31213221536436,103.848328363879", "1.31288473199114,103.849575392632"]
];
console.log(
input.map(
subarr => subarr.map(
str => str.split(',').map(Number)
)
)
);
I have no idea how to read this, is it possible to store the result into a variable?
– ITnyp
Nov 8 at 9:21
Just put something likevar somevar =in place ofconsole.log(, theconsole.login the code above is just to demonstrate that it results in the output you want
– CertainPerformance
Nov 8 at 9:23
Nice! Exactly how i want it. Thanks again for the help!
– ITnyp
Nov 8 at 9:25
are you still there? I don't know why but I am return with a different result when I use it on my code
– ITnyp
Nov 8 at 9:35
The result I am returned is nested in an array
– ITnyp
Nov 8 at 9:37
|
show 3 more comments
up vote
1
down vote
accepted
map each item in the outer array, then .map each subarray and split by commas, and map again by Number to transform the strings to numbers:
const input = [
["1.31069258855609,103.848649478524", "1.31138534529796,103.848923050526"],
["1.31213221536436,103.848328363879", "1.31288473199114,103.849575392632"]
];
console.log(
input.map(
subarr => subarr.map(
str => str.split(',').map(Number)
)
)
);
I have no idea how to read this, is it possible to store the result into a variable?
– ITnyp
Nov 8 at 9:21
Just put something likevar somevar =in place ofconsole.log(, theconsole.login the code above is just to demonstrate that it results in the output you want
– CertainPerformance
Nov 8 at 9:23
Nice! Exactly how i want it. Thanks again for the help!
– ITnyp
Nov 8 at 9:25
are you still there? I don't know why but I am return with a different result when I use it on my code
– ITnyp
Nov 8 at 9:35
The result I am returned is nested in an array
– ITnyp
Nov 8 at 9:37
|
show 3 more comments
up vote
1
down vote
accepted
up vote
1
down vote
accepted
map each item in the outer array, then .map each subarray and split by commas, and map again by Number to transform the strings to numbers:
const input = [
["1.31069258855609,103.848649478524", "1.31138534529796,103.848923050526"],
["1.31213221536436,103.848328363879", "1.31288473199114,103.849575392632"]
];
console.log(
input.map(
subarr => subarr.map(
str => str.split(',').map(Number)
)
)
);map each item in the outer array, then .map each subarray and split by commas, and map again by Number to transform the strings to numbers:
const input = [
["1.31069258855609,103.848649478524", "1.31138534529796,103.848923050526"],
["1.31213221536436,103.848328363879", "1.31288473199114,103.849575392632"]
];
console.log(
input.map(
subarr => subarr.map(
str => str.split(',').map(Number)
)
)
);const input = [
["1.31069258855609,103.848649478524", "1.31138534529796,103.848923050526"],
["1.31213221536436,103.848328363879", "1.31288473199114,103.849575392632"]
];
console.log(
input.map(
subarr => subarr.map(
str => str.split(',').map(Number)
)
)
);const input = [
["1.31069258855609,103.848649478524", "1.31138534529796,103.848923050526"],
["1.31213221536436,103.848328363879", "1.31288473199114,103.849575392632"]
];
console.log(
input.map(
subarr => subarr.map(
str => str.split(',').map(Number)
)
)
);answered Nov 8 at 9:18
CertainPerformance
63.1k143051
63.1k143051
I have no idea how to read this, is it possible to store the result into a variable?
– ITnyp
Nov 8 at 9:21
Just put something likevar somevar =in place ofconsole.log(, theconsole.login the code above is just to demonstrate that it results in the output you want
– CertainPerformance
Nov 8 at 9:23
Nice! Exactly how i want it. Thanks again for the help!
– ITnyp
Nov 8 at 9:25
are you still there? I don't know why but I am return with a different result when I use it on my code
– ITnyp
Nov 8 at 9:35
The result I am returned is nested in an array
– ITnyp
Nov 8 at 9:37
|
show 3 more comments
I have no idea how to read this, is it possible to store the result into a variable?
– ITnyp
Nov 8 at 9:21
Just put something likevar somevar =in place ofconsole.log(, theconsole.login the code above is just to demonstrate that it results in the output you want
– CertainPerformance
Nov 8 at 9:23
Nice! Exactly how i want it. Thanks again for the help!
– ITnyp
Nov 8 at 9:25
are you still there? I don't know why but I am return with a different result when I use it on my code
– ITnyp
Nov 8 at 9:35
The result I am returned is nested in an array
– ITnyp
Nov 8 at 9:37
I have no idea how to read this, is it possible to store the result into a variable?
– ITnyp
Nov 8 at 9:21
I have no idea how to read this, is it possible to store the result into a variable?
– ITnyp
Nov 8 at 9:21
Just put something like
var somevar = in place of console.log(, the console.log in the code above is just to demonstrate that it results in the output you want– CertainPerformance
Nov 8 at 9:23
Just put something like
var somevar = in place of console.log(, the console.log in the code above is just to demonstrate that it results in the output you want– CertainPerformance
Nov 8 at 9:23
Nice! Exactly how i want it. Thanks again for the help!
– ITnyp
Nov 8 at 9:25
Nice! Exactly how i want it. Thanks again for the help!
– ITnyp
Nov 8 at 9:25
are you still there? I don't know why but I am return with a different result when I use it on my code
– ITnyp
Nov 8 at 9:35
are you still there? I don't know why but I am return with a different result when I use it on my code
– ITnyp
Nov 8 at 9:35
The result I am returned is nested in an array
– ITnyp
Nov 8 at 9:37
The result I am returned is nested in an array
– ITnyp
Nov 8 at 9:37
|
show 3 more comments
up vote
0
down vote
A function to do the job:
function splitMyArray(arr) {
for (var i = 0; i < arr.length; ++i) {
var line = arr[i];
for (var k = 0; k < line.length; ++k) {
var parts = line[k].split(',');
line[k] = [parseFloat(parts[0]), parseFloat(parts[1])];
}
}
return arr;
}
Usage example:
var myArr = [
["1.31,103.84", "1.32,103.85"],
["1.39,103.77", "1.40,103.78"]
];
var splitted = splitMyArray(myArr);
console.log(splitted);
add a comment |
up vote
0
down vote
A function to do the job:
function splitMyArray(arr) {
for (var i = 0; i < arr.length; ++i) {
var line = arr[i];
for (var k = 0; k < line.length; ++k) {
var parts = line[k].split(',');
line[k] = [parseFloat(parts[0]), parseFloat(parts[1])];
}
}
return arr;
}
Usage example:
var myArr = [
["1.31,103.84", "1.32,103.85"],
["1.39,103.77", "1.40,103.78"]
];
var splitted = splitMyArray(myArr);
console.log(splitted);
add a comment |
up vote
0
down vote
up vote
0
down vote
A function to do the job:
function splitMyArray(arr) {
for (var i = 0; i < arr.length; ++i) {
var line = arr[i];
for (var k = 0; k < line.length; ++k) {
var parts = line[k].split(',');
line[k] = [parseFloat(parts[0]), parseFloat(parts[1])];
}
}
return arr;
}
Usage example:
var myArr = [
["1.31,103.84", "1.32,103.85"],
["1.39,103.77", "1.40,103.78"]
];
var splitted = splitMyArray(myArr);
console.log(splitted);
A function to do the job:
function splitMyArray(arr) {
for (var i = 0; i < arr.length; ++i) {
var line = arr[i];
for (var k = 0; k < line.length; ++k) {
var parts = line[k].split(',');
line[k] = [parseFloat(parts[0]), parseFloat(parts[1])];
}
}
return arr;
}
Usage example:
var myArr = [
["1.31,103.84", "1.32,103.85"],
["1.39,103.77", "1.40,103.78"]
];
var splitted = splitMyArray(myArr);
console.log(splitted);
edited Nov 8 at 9:33
answered Nov 8 at 9:25
Rodrigo
998416
998416
add a comment |
add a comment |
ITnyp is a new contributor. Be nice, and check out our Code of Conduct.
ITnyp is a new contributor. Be nice, and check out our Code of Conduct.
ITnyp is a new contributor. Be nice, and check out our Code of Conduct.
ITnyp is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53204619%2fangularjs-split-array%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Fetched from an api
– ITnyp
Nov 8 at 9:16
I am trying to plot a polyline in my map
– ITnyp
Nov 8 at 9:17
Ohh, sorry it was a typo edited it
– ITnyp
Nov 8 at 9:18