H
H
heisenberg12021-06-09 00:26:57
JavaScript
heisenberg1, 2021-06-09 00:26:57

How to pass the result to an object as numbers?

Good day.
Tell me how to make the array result in numbers, not strings, and the result can be transferred to an object (for example, coordinates)?


const loc = {
lat: [35.65000, 35.70000],
lng: [139.70000, 139.80000]
};
const getRandomLocation = loc => _ => {
const [lat, lng] = Object.values(loc).map(([min, max]) => (Math.random() * (max - min) + min) .toFixed(5));
return [lat, lng]
};
const RandomLocation = getRandomLocation(loc);
for (let i = 0; i < 1; i++)
RandomLocation()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Dubrovin, 2021-06-09
@alekcena

Put + in front of the variable
Example

let a = "12";
let b = +a;
console.log(typeof(a),typeof(b));

Option 2
Example:
let a = "12";
let b = Number(a);
console.log(typeof(a),typeof(b));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question