Answers for "get the value of the first key"

1

how to get the first key in a n object in javascript

var obj = { "a" : 1, "b" : 2, "c" : 3};
alert(Object.keys(obj)[0]);
// alerts "a"
let objLength = Object.keys(obj).length
console.log(objLength)
// Logs 3 as "obj" has 3 keys
var objValue = Object.values(obj)[0]
console.log(objValue)
// Logs "1" as the value of the first key(a) is "1"
Posted by: Guest on September-01-2021
6

get first object key javascript

var example = {
    foo1: { /* stuff1 */},
    foo2: { /* stuff2 */},
    foo3: { /* stuff3 */}
};

let [first] = Object.keys(example)

console.log(first)
Posted by: Guest on April-27-2020

Code answers related to "get the value of the first key"

Code answers related to "Javascript"

Browse Popular Code Answers by Language