0

I have json result like this

{
   "modelList":["modelName1","modelName2"],
   "modelNamesList":["modelName1","modelName2"],
   "yearList":["2021","2020","2019","2018"]
}

I need only years list from above object so I am not getting how to do that, can anyone help me, thank you

I have done something like this

home.component.ts

 export class HomeComponent implements OnInit {

    catlogData: any ={
                "modelList":["modelName1","modelName2"],
                "modelNamesList":["modelName1","modelName2"],
                "yearList":["2021","2020","2019","2018"]
    };


    ngOnInit(): void {}

home.component.html

<ul *ngFor="let a of catlogData">
    <li>year:{{a.yearList[i]}}
    </li>
</ul>
2
  • Does this answer your question? How to iterate object keys using *ngFor Commented Jan 19, 2021 at 18:31
  • You can apply *ngFor on catlogData.yearList, you can access directly json property with .. Commented Jan 19, 2021 at 18:33

1 Answer 1

2

You can directly access the yearsList from catlogData since it's an Object(catlogData.yearsList). Incase if you want iterate whole catlogData object, Check this answer

Try like this

 <div>
   <ul *ngFor="let year of catlogData.yearList">
     <li>years: {{ year }}</li>
   </ul>
 </div
Sign up to request clarification or add additional context in comments.

1 Comment

happy to help!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.