Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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"
Comment

javascript object first key

var person = {"name":"Steve","age":43};
var firstKeyValue = person[Object.keys(person)[0]]; //"Steve"
Comment

get first object key javascript

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

let [first] = Object.keys(example)

console.log(first)
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript celcius to farenheit 
Javascript :: how to see in how many servers your discord bot is d.js 
Javascript :: how to get last path from url in javascript 
Javascript :: update create react app 
Javascript :: Slick slider arrows change 
Javascript :: slugify text javascript 
Javascript :: number with commas js 
Javascript :: remove empty lines regex 
Javascript :: use json file for data jquery 
Javascript :: is advanced functions harder than calculus 
Javascript :: javascript remove line breaks from string 
Javascript :: access-control-allow-origin nodejs express 
Javascript :: javascript get number of elements in object 
Javascript :: datatable scroll horizontal 
Javascript :: javascript throw vs console.error 
Javascript :: Get List of all files in a directory in Node.js 
Javascript :: javascript get element height 
Javascript :: remove previous datatable instance 
Javascript :: href back page javascript 
Javascript :: javascript void 
Javascript :: javascript get css variable 
Javascript :: ts-node dotenv 
Javascript :: node js for loop 
Javascript :: javascript time execution 
Javascript :: js is function 
Javascript :: get window size javascript 
Javascript :: jquery checkbox checked value 
Javascript :: node js procfile heroku starter 
Javascript :: js remove the last character of a string 
Javascript :: js string limit length 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =