i write javascript code to parse json and use the data, the json file contain date and time, latitude and longitude data :
const api_url = 'json.php'
async function getjson() {
const response = await fetch(api_url);
const data = await response.json();
console.log(data)
the console log show 260 array, but the latest date and time is on potition array : 260 my question is how i can get the latest json data sort in date and time?
CodePudding user response:
If you know the array is sorted and want to get the last item in the array, you can use the length property to calculate the index of the last item e.g.
const latest = data[data.length -1];