Navigate back to the homepage

How to get value from object by key in typescript?

Infinitbility
TypeScript
May 7th, 2022 · 1 min read
keep affilitate

Hi Friends 👋,

Welcome to Infinitbility ❤️!

Today, we will learn how to get value from an object by key in typescript, here we will use some basic syntax to get value from an object.

Here, we will see

  1. Access object value using the dot method
  2. Access object value using bracket method ( we can also use it for dynamic value access )

In the code below, we create a sample object variable to store sample dog data.

after creation, I use variables to access the object values.

Let’s dive into code…

1// create sample object variable
2const animals = {
3 id: 1,
4 name: "dog",
5 age: 5
6};
7
8// access value by dot syntax
9animals.id;
10
11// access value by bracket ( we can also use it for dynamic value access )
12animals["name"]

When you run the above code, you will get the id and name keys value. For now, let’s check the output.

TypeScript, get value from object by key example
TypeScript, get value from object by key example

All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

melio affilitate

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

How to get first 5 elements of array in javascript?

Example of get first 5 elements of array in javascript with step by step guide.

May 6th, 2022 · 1 min read

How to get number of keys of object in javascript?

Example of get number of keys of object in javascript with step by step guide.

May 5th, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]