Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the first key of a javascript object

Tags:

json

jquery

A very basic question, but I can't find the 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 obtain id_ship

Thank you in advance

like image 349
Thibault Van Campenhoudt Avatar asked Apr 28 '15 10:04

Thibault Van Campenhoudt


1 Answers

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

Object.keys(obj)[0];
like image 173
Tushar Avatar answered Nov 09 '22 17:11

Tushar