
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Convert a list of string coords into two float lists of Lat/Longitude coordinates in JavaScript?
Let’s say the following are our coordinates −
var listOfStrings = ["10.45322,-6.8766363", "78.93664664,-9.74646646", "7888.7664664,-10.64664632"];
To convert the above into two float lists of Latitude and Longitude, use split() on the basis of comma(,) along with map().
Example
var listOfStrings = ["10.45322,-6.8766363", "78.93664664,-9.74646646", "7888.7664664,-10.64664632"]; var latitude = []; var longitude = []; listOfStrings.forEach(obj => obj.split(',') .map(Number) .forEach((value, index) => [latitude, longitude][index].push(value)) ); console.log("All positive value is latitude=") console.log(latitude); console.log("All negative value is longitude=") console.log(longitude);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo180.js.
Output
This will produce the following output −
PS C:\Users\Amit\javascript-code> node demo180.js All positive value is latitude= [ 10.45322, 78.93664664, 7888.7664664 ] All negative value is longitude= [ -6.8766363, -9.74646646, -10.64664632 ]
- Related Articles
- Convert list into list of lists in Python
- How to convert string into float in JavaScript?
- Convert a list into tuple of lists in Python
- How to convert a list of lists into a single list in R?
- Python - Convert a list of lists into tree-like dict
- Convert two lists into a dictionary in Python
- Convert a string representation of list into list in Python
- Python program to convert a list into a list of lists using a step value
- Convert list of string into sorted list of integer in Python
- Python - Convert List of lists to List of Sets
- How to convert a list of characters into a string in C#?
- Java program to convert a list of characters into a string
- C# program to convert a list of characters into a string
- How can we convert a list of characters into a string in Python?
- How to convert dictionary into list of JavaScript objects?

Advertisements