Try to search your question here, if you can't find : Ask Any Question Now ?

Push nested Json Values with unknown path into Array in Javascript

HomeCategory: stackoverflowPush nested Json Values with unknown path into Array in Javascript
Avatarpushpa asked 4 weeks ago

So I don’t know why Im struggling with this. It seems like I should be able to use Lodash or something to do this I would think.

I have an object that looks like.

  { "fdjkafdajkfasfjkdaslj" {
      "-LMUD-2APhiSLkEtVbM": {
        "profileName": "bob",
            "profilePic": "www.profilepic.com",
            "score": 73,
            "teamName": "lzs"
        }
    }
  }

I will not know the first to keys in the structure. Example from above.
"fdjkafdajkfasfjkdaslj" or "-LMUD-2APhiSLkEtVbM".

I really just need to push these key values into an array.

       "profileName": "bob",
        "profilePic": "www.profilepic.com",
        "score": 73,
        "teamName": "lzs"

What is the best way to accomplish this in javascript (im actually a React.js)? I was thinking Lodash maybe but haven’t found anything yet? Most of my searches for retrieving nested Key/Value data in Json indicate you would need a path but I will not have the path in this scenario. I won’t know the top 2 keys in this object. The only thing I have is this predicable object structure with 2 unknown keys before my key/value data.

1 Answers
Best Answer
Avatarnaveen answered 4 weeks ago
Your Answer

7 + 0 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com