0

I have an array like so:

[
 {
  lookups: [], 
  rows: [{data: {a: 1, b: 2}}, {data: {a: 3, b: 4}}], 
  title: "Table 1", 
  columns: [{name: "a"}, {name: "b"}]
 },
 {
  lookups: [],
  rows: [{data: {c: 5, d: 6}}, {data: {c: 7, d: 8}}],
  title: "Table 2",
  columns: [{name: "c"}, {name: "d"}]
 }
]

After I select the correct object (which I am using Array.find() using the title to do). I need to be able to go through the rows array and try to get each value for a particular string that I have (e.g. If I have a string value of "a" then I would like to get the values 1 and 3 back).

Help would be very much appreciated.

Thanks for your time.

1 Answer 1

2

Use simple mapping. Suppose you have property name stored in variable named prop

data = obj.rows.map(({data}) => data[prop])
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.