0

I am trying to take the last element in a JSON. I know order is not preserved, but the keys are unix timestamps so I can just sort. I am working from this question:

get last element of a json object in javascript

But I get nothing logged to the console and no errors.

my code:

var mydata = {"1509937402379":"7348.01","1509937412486":"7348.01","1509937422253":"7348.01","1509937426286":"7348.01","1509937430066":"7345.54"}

console.log(mydata[Object.keys(obj).sort().pop()]);

https://jsfiddle.net/Lmb5sd1m/1/

user2242044
  • 8,803
  • 25
  • 97
  • 164

1 Answers1

3

You missed.. .You require to use Object.keys(mydata).

var mydata = {"1509937402379":"7348.01","1509937412486":"7348.01","1509937422253":"7348.01","1509937426286":"7348.01","1509937430066":"7345.54"}

Review same fiddle https://jsfiddle.net/Lmb5sd1m/1/

Dipak
  • 2,248
  • 4
  • 22
  • 55