Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 76028

How to find object property name by matching its id

$
0
0

I have a simple json data,I need to get the name from object by comparing its id.Suppose I have a number 2,I need to compare with object's id,if it is equal to 2 then I need to get matching object's property 'name' from object.Like here it will be matching name 'dog' in my json. Here is the code below https://stackblitz.com/edit/angular-dtyvrc?file=src%2Fapp%2Fapp.component.ts

app.component.html

<hello name="{{ name }}"></hello>
<p>
  Start editing to see some magic happen :)
</p>

app.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {
  name = 'Angular';
  ngOnInit() {
  let statusdata1 = [{"id":1,"name":"cat"},{"id":2,"name":"dog"}]
  console.log('dog')
  }
}

Viewing all articles
Browse latest Browse all 76028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>