उदाहरण
split() और map() का उपयोग करके स्ट्रिंग कोऑर्डिनेट्स को फ्लोट ऐरे में बदलें।
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);
प्रोग्राम चलाने के लिए:
node fileName.js
आउटपुट
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 ]