Get first key of javascript object

A very simple question, but I can not find a solution:

I have a jquery object (given in console.log ):

 { id_ship: "1", id_company: "1", code: "DE", // other properties... } 

I just want to get the first key on the object. In this case, I want to get id_ship

Thank you in advance

+6
source share
1 answer

As @RoryMcCrossan said, order in an object is not guaranteed. But if you still want to get the first key, you can use:

 Object.keys(obj)[0]; 
+10
source

Source: https://habr.com/ru/post/986125/


All Articles