1

I have an array of nested objects. I am trying to iterate though the array and get back a list of ids from the nested objects.

        "group": [
        {
          "groupId": "1",
          "subGroup": {
            "id": "44",
            "name": "Testing",
          }
        },
 {
          "groupId": "2",
          "subGroup": {
            "id": "45",
            "name": "Testing",
          }
        },
 {
          "groupId": "3",
          "subGroup": {
            "id": "46",
            "name": "Testing",
          }
        }
      ]

I am trying to return a list of ids like so => [44, 45, 46]

I tried const result = map(path("subGroup", "id"), group), but it did not produce the result I need.

1 Answer 1

2

The approach you've taken is fine, except that R.path expects an array of path indexes rather than multiple arguments.

map(path(["subGroup", "id"]), group)

Alternatively, you could also just use the map method of arrays to achieve the same result.

group.map(g => g.subGroup.id)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.