Skip to content

Transform Array to Object  #57

@turbopasi

Description

@turbopasi

If part of the data looks like this

someArray : [
  { id : "A", value : "10" },
  { id : "B", value : "20" },
  { id : "C", value : "30" }
]

can this part be transformed to

someObject : {
  A : { id : "A", value : "10" },
  B : { id : "B", value : "20" },
  C : { id : "C", value : "30" }
}

?

Maybe if the run function in an operate block gets passed the whole item you could do something like this

operate : [
  {
    run : function (val, item) {
      item.someObject[val.id] = val;
      return val;
    },
    on : "someArray"
  }
]

Just a naive idea basically but I wondered if there is a functionality already built-in. Mapping an Array into an Object is something I use very often.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions