Answers for "javascript take object first value and make it a key"

8

js get first object value

var obj = { first: 'someVal' };
obj[Object.keys(obj)[0]]; //returns 'someVal'
Posted by: Guest on November-03-2020
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

Code answers related to "javascript take object first value and make it a key"

Code answers related to "Javascript"

Browse Popular Code Answers by Language