0
{
 "Petition to file": [
 {
 "description": "fileing description",
 "period": "30 days",
 "fees": "500"
 }
 ],
 "Appearing before inspection": [
 {
 "description": "Appearence Description",
 "period": "10 days",
 "fees": "1500"
 }
 ],
 "Passing orders for a recording of statements": [
 {
 "description": "passing order description",
 "period": "50 days",
 "fees": "1000"
 }
 ],
 "Hearing of petition": [
 {
 "description": "Hearing of petition description",
 "period": "55 days",
 "fees": "2000"
 }
 ],
 "Decree of petition": [
 {
 "description": "decreeof description",
 "period": "70 days",
 "fees": "5000"
 }
 ]
}

How to get the values of nested child headings. It is dynamic content .Also i need to fetch the values of nested objects that is period,fess,description . I'm using typescript program that is in angular cli

Patricio Vargas
5,60014 gold badges57 silver badges107 bronze badges
asked Nov 21, 2019 at 6:08
4
  • 2
    did you attempt anything at all ? Commented Nov 21, 2019 at 6:10
  • 2
    There's no such thing as a "JSON Object" Commented Nov 21, 2019 at 6:19
  • The point is the title(example:Petition to file) of nested object will be dynamic by server response . Commented Nov 21, 2019 at 6:19
  • use Object.keys to get the dynamic keys and map them into an array Commented Nov 21, 2019 at 6:21

3 Answers 3

1

here is complete working example StackBlitz Link, Your main logic of traversing dynamic object entries is...

ngOnInit(){
 Object.keys(this.datafromDatabase).forEach(data =>{ 
 this.datafromDatabase[data].map(key =>{
 this.data.push(key)
 });
 })
}

Your Template file is...

<div *ngFor="let key of data">
 {{key.description}}
</div>
<div>
 {{data |json}}
</div>
answered Nov 21, 2019 at 7:16
Sign up to request clarification or add additional context in comments.

Comments

0
var something = consts['Petition to file'];

usually thats the way to get the values inside keys

so now the new variable something =

[
 {
 "description": "fileing description",
 "period": "30 days",
 "fees": "500"
 }
 ]

now if u want description

var descriptionVariable = consts['description'];

so descriptionVariabe's value is fileing description

Erik Philips
54.9k11 gold badges133 silver badges158 bronze badges
answered Nov 21, 2019 at 6:36

Comments

0

let list = {
 "Petition to file": [
 {
 "description": "fileing description",
 "period": "30 days",
 "fees": "500"
 }
 ],
 "Appearing before inspection": [
 {
 "description": "Appearence Description",
 "period": "10 days",
 "fees": "1500"
 }
 ],
 "Passing orders for a recording of statements": [
 {
 "description": "passing order description",
 "period": "50 days",
 "fees": "1000"
 }
 ],
 "Hearing of petition": [
 {
 "description": "Hearing of petition description",
 "period": "55 days",
 "fees": "2000"
 }
 ],
 "Decree of petition": [
 {
 "description": "decreeof description",
 "period": "70 days",
 "fees": "5000"
 }
 ]
}
for (let [key, value] of Object.entries(list)) {
 	console.log(key);
	console.log(value);
}

Use Object.entries

answered Nov 21, 2019 at 6:45

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.