7

ARRAY LIKE OBJECTS

Long story short, i am fiddling a bit around with javascripts, a json object a php script created and encountered "array-like" objects. I tried to use .forEach and discovered it doesnt work on those.

Easy easy, there is always Array.from()..just..it doesnt work, well it does work for one subset called ['data'] which contains the actual rows i generate a table from, but for the ['meta'] part of the json object it just returns a length 0 object..me no understanderino

at least something cheered me up when researching, it was an article with the quote: "Finally, the spread operator. It’s a fantastic way to convert Array-like objects into honest-to-God arrays."
I like honest-to-God arrays..or in my case honest to Fortuna..doesnt solve my problem though

Comments
  • 2
    You can use Object.keys() to iterate over object properties:

    var a = { meta: ..., data: ...};
    for (let key of Object.keys(a)) {
    console.log(a[key]);
    }
  • 2
    @closurepointer & @bigus-dickus

    yeah...that will do. it turns out i am actual retarded..i am a bit familiar with php and not so much with jscript..so i assumed the index of an array can be string or integer..which is of course not true..they way my json is build it works perfectly with the data set cause its an "honest-to-god" Array while the meta data set is not.
Add Comment