muelleste
muelleste

Reputation: 41

Angular 4 - Get Value from JSON by Key

I want to get the value by the key of this json. The key is description and i want it in my console.log, i don't really get how to get this value, the filtering before worked fine.

{
    "id": "149",
    "description": "Try"
}

Thanks!

Upvotes: 1

Views: 14209

Answers (2)

Vivek Doshi
Vivek Doshi

Reputation: 58533

const dummy = {
  id : '1',
  description : 'Wow awesome'
};

console.log(dummy.description);

//-------------------------------------

const descData = dummy.description;

console.log(descData);

variableName['description'] or variableName.description

Upvotes: 2

Rupal
Rupal

Reputation: 1109

First You need to parse it using JSON.parse. Then using . or [] you can access. For Ex:-

var a = '{
    "id": "149",
    "description": "Try"
}'

b = JSON.parse(a)

b['description'] or b.description FOr more reference you can study here

Upvotes: 2

Related Questions