Issue
I have a response for Angular 11 TypeScript code like:
{
"Id": "12345",
"length": [
{
"a": {
"1": {
"test": [
{
"days": "20"
}
]
}
}
}
]
}
It is unable to fetch data as one parameter is "1
". It’s giving a compilation issue when trying to print the value of days like:
console.log(length[0].a.1.test[0].days);
If it’s "one
" instead of "1
" it’s working fine:
console.log(length[0].a.one.test[0].days);
Solution
Try this working solution. It should work now.
const data = {
"Id": "12345",
"length": [
{
"a": {
"1": {
"test": [
{
"days": "20"
}
]
}
}
}
]
}
console.log(data.length[0].a[1].test[0].days) // returns "20"
Answered By - Yuva Raj
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.