Hi Friends đź‘‹,

Welcome To Infinitbility! ❤️

Today, we will learn to get the first value from a JSON object in javascript, here we will Object.values() method to get the first value from the object.

What is Object.values()

The Object.values() method returns an array of a given object’s own enumerable property values, in the same order as that provided by a for…in the loop. (The only difference is that a for…in loop enumerates properties in the prototype chain as well.)

– MDN

The Object.values() will return an only array of values available in an object, now we can easily get the first value from the JSON object using array 0th index.

let’s see how can do in javascript

const domain = {
  name: "Infinitbility",
  dob: "26-7-2020",
  domain: "infinitbility.com",
  email: "[email protected]",
};

console.log(Object.values(domain)[0])

Surely, it will log Infinitbility in the console, because it’s the first value.

let’s check the output.

JavaScript, get first value from json object example
JavaScript, get first value from json object example

All the best đź‘Ť.