0

I am trying to filter out an Object of Arrays wherein I have to filter out the 'designation' 'options' of a key.

My row Object looks like.

{id: 1, columns: Array(5)}
columns: (5) [InputDate, InputSelect, InputSelect, InputSelect, InputString]
id: 1
__proto__: Object

One of the columns Array where data is looks like this.

InputSelect
name: "designation"
options: Array(3)
0: {name: "Entry", value: "ENTRY"}
1: {name: "Mid", value: "MID"}
2: {name: "Experienced", value: "EXPERIENCE"}
length: 3
__proto__: Array(0)

Now I have to search inside the columns Arrays and filter out the options of "ENTRY" if the Arrays name property is 'designation' so as to return the updated Object having this filtered value.

What I am trying now is

row.columns.map( key =>  { 
            if (key.name === 'designation') {
                key.options.filter( r => r.value === "ENTRY" )
            }

But it doesn't seem to be updating the row Object.

Sam_2207
  • 2,759
  • 2
  • 9
  • 15
  • Does this answer your question? [Filtering array of objects with arrays based on nested value](https://stackoverflow.com/questions/38375646/filtering-array-of-objects-with-arrays-based-on-nested-value) – Heretic Monkey May 11 '20 at 15:01
  • 4
    Both `map` and `filter` return arrays; use those return values. – Heretic Monkey May 11 '20 at 15:01
  • @HereticMonkey, I tried with Spread Operator example from this link but it didn't work. – Sam_2207 May 11 '20 at 15:47
  • 1
    Please [edit] your question to show how you implemented the answer(s) to the question with the data. Please use a [mre], preferably using a [Stack Snippet](https://meta.stackoverflow.com/q/358992/215552) (icon looks like `<>` in the editor toolbar) so that others can run the code, with example data, here on Stack Overflow. – Heretic Monkey May 11 '20 at 15:54

1 Answers1

0

This should solve your problem.

row.columns.filter(x=>x.name=="designation").map(i=>i.options.filter(z=>z.name==="Entry"));
kokila
  • 294
  • 2
  • 8