How to retrieve value from array of array of object angular 5

array in angular 8
angular list of objects
array of objects in angular 6
angular 4 array of objects
ngfor

I have JSON like this, which is stored in variable.

data=[  
   [  
      {  
         "fdate":"01-01-2018",
         "pdate":"31-12-2018",
         "range":"01-01-2018 - 31-12-2018",
         "nlist":[  ],
         "nplist":[  ]
      }
   ],
   [  
      {  
         "fdate":"01-01-2018",
         "pdate":"31-12-2018",
         "range":"01-01-2018 - 31-12-2018",
         "nlist":[  ],
         "nplist":[  ]
      },
      {  
         "efdate":"21-01-2018",
         "expdate":"31-12-2018",
         "range":"21-01-2018 - 31-12-2018",
         "nlist":[  ],
         "nplist":[  ]
      }
   ]
]

How to get the range from here in typescript file, please advice.

I am trying to retrieve like this, but its not working

for(let i=0; i< this.data.length; i++){
            this.other +=  this.data[i].range;
            }
Console.log(this.other);

Please advice or let me know if any better way to do this

You can do it like this:

for(let i=0; i < this.data.length;i++){
    for(let j=0; j < this.data[i].length;j++){
        this.other +=  this.data[i][j].range;
        console.log(this.data[i][j].range); // What you want to do here...
    }   
}

Here is working example: https://stackblitz.com/edit/angular-8j5hkk

Hope this help you!!!!

Typescript, In Application development, We used to get the use cases where data retrieved This section will see how we can convert Object to Array in Angular and Typescript with examples. And callback is executed for each element of an object. Angular · Angular 5 · Angular 6 · Javascript Documentation · Es6/​Es2015 · Es7/  Hi. In this article we will cover on how to implement angular push element in array. I’m going to show you about angular push object into array. if you have question about angular object push key value then i will give simple example with solution. you will learn push object in array in angular.

var data=[  
   [  
      {  
         "fdate":"01-01-2018",
         "pdate":"31-12-2018",
         "range":"01-01-2018 - 31-12-2018",
         "nlist":[  ],
         "nplist":[  ]
      }
   ],
   [  
      {  
         "fdate":"01-01-2018",
         "pdate":"31-12-2018",
         "range":"01-01-2018 - 31-12-2018",
         "nlist":[  ],
         "nplist":[  ]
      },
      {  
         "efdate":"21-01-2018",
         "expdate":"31-12-2018",
         "range":"21-01-2018 - 31-12-2018",
         "nlist":[  ],
         "nplist":[  ]
      }
   ]
]

var calc = calculateRange(data);
console.log(calc)
function calculateRange(_data){
   var r = "";
   for(var i=0;i<_data.length;i++){
       var isArray = Array.isArray(_data[i]);
       if(isArray){
        r+=calculateRange(_data[i]);
       }else{
        var x = _data[i].range;
        r+= typeof x != "undefined"? x:"";
       }
   }
   return r;
}

Data Structures: Objects and Arrays :: Eloquent JavaScript, Say, for example, that we want to represent a collection of the numbers 2, 3, 5, 7, and 11. In the second, we access the property named max in the Math object (​which is Both string and array values contain, in addition to the length property,​  How to retrieve value from array of array of object angular 5. Ask Question Asked 1 year, 8 months ago. In html page you can retrieve like this

this.data=[
  [
     {
        "fdate":"01-01-2018",
        "pdate":"31-12-2018",
        "range":"01-01-2018 - 31-12-2018",
        "nlist":[  ],
        "nplist":[  ]
     }
  ],
  [
     {
        "fdate":"01-01-2018",
        "pdate":"31-12-2018",
        "range":"01-01-2018 - 31-12-2018",
        "nlist":[  ],
        "nplist":[  ]
     },
     {
        "efdate":"21-01-2018",
        "expdate":"31-12-2018",
        "range":"21-01-2018 - 31-12-2018",
        "nlist":[  ],
        "nplist":[  ]
     }
  ]
]
for(let i=0; i< this.data.length; i++){
for(let t = 0; t < this.data[i].length; t++) {
     console.log(this.data[i][t].range);
      }
    }
  

Array.prototype.shift(), The shift() method removes the first element from an array and returns that 5. console.log(array1);. 6. // expected output: Array [2, 3]. 7. ​. 8 Reset. The source for this interactive example is stored in a GitHub repository. Objects which do not contain a length property reflecting the last in a series of  Typescript Code. Let us assume that you have an object declared multiple properties. First Get the named keys using object.keys() method. This method retrieves keys from the given object and returns an array of keys. Using map() method with a defined callback. And callback is executed for each element of an object.

Array.prototype.find(), Object to use as this inside callback . Return value. The value of the first element in the array that satisfies the provided testing function. Otherwise  JavaScript : find an object in array based on object's property (and learn about the "find" function) Published on March 20, 2017 March 20, 2017 • 304 Likes • 48 Comments Report this post

JSON Arrays, In JSON, array values must be of type string, number, object, array, boolean or null. In JavaScript You access the array values by using the index number:  An array has, alongside its elements, a special property named length and a generous collection of methods for manipulating the elements. They represent the real power of arrays. You can search, sort, delete, insert and even simulate behavior of other collection data types, like queue and stack. arrays are normal objects and their elements are

angular.forEach, The iterator function is invoked with iterator(value, key, obj) , where value is the value of an object property or an array element, key is the object property key or  Angular FormArray is an inbuilt class that tracks the value and validity state of an array of FormControl, FormGroup, or FormArray instances. For example, if one of the controls in a FormArray is invalid, an entire array becomes invalid. Angular FormArray is one of the three fundamental building blocks used to define forms in Angular, along

Comments
  • Your data is a bit wild, but to get the first range you can use data[0][0].range
  • Where do you need this value? Can you add some code?
  • What have you tried so far? Kindly post expected output
  • I have updated the question, added the ts code as well, please guide or any better way to do this.
  • Even console.log is spelled wrong. I'm pretty sure this is an async problem; post the code you are using, otherwise nobody can help you
  • Thank you for the response, but its showing undefined, could you please show me the working example, any help would be appreciable.
  • Thank you foe the response, its running in infinite loop and showing false.. false..in console, please advice.
  • Can you give the trace of _data[i]
  • its showing (99586)false in app.component.ts: line number 357
  • It's a wild guess may be its occuring because every element is coming as STRING or object. Can you try the same with var rData = JSON.parse(data); and var calc = calculateRange(rData);
  • Thank you for the response, its working fine now, could you please guide me, how to display calc in another drop down,
  • Thank you for the response, html its showing, but in typescript its showing undefined, I need to do some more stuffs in ts file, please advice