All TalkersCode Topics

Follow TalkersCode On Social Media - A Social Media Network for developers Join Now ➔

JavaScript Object Get Value By Key

Last Updated : Mar 11, 2024

JavaScript Object Get Value By Key

In this tutorial we will show you the solution of JavaScript object get value by key, there are many ways to get object value by keys, let us understand them one by one.

As, we already said that there are many ways to done this article.

Step By Step Guide On JavaScript Object Get Value By Key :-

Here, in this article we are going to use two methods that is using dot notation and using square brackets. Let us understand both of them with help of codes.

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>convert object to array using JavaScript</title>
  var values = {
     name: "Chris Evans",
     age: 39,
// using square bracket
console.log(values["name"]); console.log(values["age"]); console.log(values["marks"]);
// using dot notation
  1. First, we write <! DOCTYPE html> which we used as an instruction to the web browser about what version of HTML file is written in.
  2. Secondly, the <html> tag is used to indicate the beginning of an HTML document.
  3. As above now <head> tag is used to contain information about web page. In this tag a <title> tag is used which helps us to specify a webpage title. Both <head> and <title> tags are Paired tags. So, both have </head> and </title> ending tags respectively.
  4. Here, then we create a body tag. All the content which we want to show on browser’s screen or display is always written inside this codes.
  5. Hence, in this article you will see that here we create an object named values using var. and after that we feed some values in this variable.
  6. As you can see there are three columns or say three keys that are name, age and marks.
  7. Now, after this to show or get values by keys of object, we create two methods. First one is using dot notation and other is using square brackets.
  8. In first one, we use console.log to print message or outputs and in this object we directly call the object and specify the name of key from which we have to get the value.
  9. Hence, it is the easiest ways to get values using keys.
  10. Now, in next one which is dot notation method, here we again create a console.log() to print messages.
  11. And inside this we give reference to the values using object and dot. Like above it the object name is values and one of its key is name. then we have to write it as
  12. At last, the <body> and <html> tags are closed with </body> and </html> respectively.

Conclusion :-

At last in conclusion, here we can say that with help of this article we are able to understand object get value by key using JavaScript.

I hope this tutorial on JavaScript object get value by key helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Ashish

Ashish is a dynamic and motivated individual with a passion of programming and an experienced programmer having 3+ years of experience in various languages like Java, Python, HTML, CSS, JavaScript, jQuery and various frameworks like Bootstrap

Follow Ashish On Linkedin 🡪