<!DOCTYPE HTML>
<
html
>
<
head
>
<
title
>
How to get the first key name
of a JavaScript object ?
</
title
>
</
head
>
<
body
style
=
"text-align:center;"
>
<
h1
style
=
"color:green;"
>
GeeksforGeeks
</
h1
>
<
p
id
=
"GFG_UP1"
style
=
"font-size: 15px; font-weight: bold;"
>
</
p
>
<
p
id
=
"GFG_UP2"
style
=
"font-size: 15px; font-weight: bold; color: green;"
>
</
p
>
<
button
onclick
=
"GFG_Fun()"
>
click here
</
button
>
<
p
id
=
"GFG_DOWN"
style
=
"color:green; font-size: 20px; font-weight: bold;"
>
</
p
>
<
script
>
var up1 = document.getElementById('GFG_UP1');
var up2 = document.getElementById('GFG_UP2');
var down = document.getElementById('GFG_DOWN');
var obj = {
"Prop_1": ["Val_11", "Val_12", "Val_13"],
"Prop_2": ["Val_21", "Val_22", "Val_23"],
"Prop_3": ["Val_31", "Val_32", "Val_33"]
};
up1.innerHTML = "Click on the button to get the "+
"first key of Object.";
up2.innerHTML = JSON.stringify(obj);
function GFG_Fun() {
down.innerHTML = "The first key = '" +
Object.keys(obj)[0] + "' <
br
> Value = '"
+ obj[Object.keys(obj)[0]] + "'";
}
</
script
>
</
body
>
</
html
>