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

js get first object value

var obj = { first: 'someVal' };
obj[Object.keys(obj)[0]]; //returns 'someVal'
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 :: how to make a deep copy in javascript 
Javascript :: add date in javascript 
Javascript :: javascript get point of line intersection 
Javascript :: nice react native shadow 
Javascript :: youtube video regex 
Javascript :: jquery window redirect with header 
Javascript :: jquery set att 
Javascript :: js escape html 
Javascript :: How to use useState Hook in React/ReactNative 
Javascript :: js get id value 
Javascript :: javascript style onclick 
Javascript :: javascript add line from file to array 
Javascript :: remove array elements javascript 
Javascript :: typeof array javascript 
Javascript :: invisible character javascript 
Javascript :: validate phone number javascript 
Javascript :: ionic cordova icon notification 
Javascript :: react check if mobile or desktop 
Javascript :: js text word wrap 
Javascript :: import jquery into js file 
Javascript :: javascript split multiple delimiters 
Javascript :: get the next character javascript 
Javascript :: js loop through array backwards with foreach 
Javascript :: javascript remove all spaces 
Javascript :: clear file upload jquery 
Javascript :: find object in array javascript with property 
Javascript :: To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function. 
Javascript :: remove a object name from spread operator 
Javascript :: javascript string contains string 
Javascript :: datatable on page change 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =