How to get first key pair element of JSON object without knowing key and deleting it in node red

Sharon Soleman picture Sharon Soleman · Feb 7, 2017 · Viewed 28.9k times · Source

I am writing a function node in node-red that is taking in a JSON object with arbitrary key val pairs:

{ 30000c690b61: "m8Jp_M7Lc0",
  30000c290bdc65: "S3qg3Rkl8Y", 
  30000c290bdf1c: "KsLpfVrR4W", 
  30000c290be5d0: "oXasuCWV_q", 
  30000c29e618: "6Q67v-gJkS" … }

I would like to access the first key pair element in this object, store it, and then delete it. I have tried multiple things, but since it is node-red, it seems to behave different

Answer

Vladu Ionut picture Vladu Ionut · Feb 7, 2017
var firstKey = Object.keys(myObject)[0];
delete myObject[firstKey ];