0

hope all of you are OK

I have the following problem, I have a complex array, with unique fields and with nested arrays fields, for example something like this:

export interface myArray: [
name: string;
position: number;
weight: number;
subArray: myArray2;
];

export interface myArray2: [
other: string;
other2: string;
otherSubArray: myArray3;
];

export interface myArray3: [
other3: number;
other4: string;
]

And I don't know if it's possible to search by a value, but comparing all the fields (automatically).

Do you know if there's a function or similar that does a filter?

I mean something like: applyFilter(myArray, 'John'); And this method search for the value 'John' in all the fields.

psd: I am using Angular 9, so basically this method will be using Typescript.

Thanks in advance, and if you need extra info feel free to ask

Alberto A.M.
  • 53
  • 1
  • 7
  • So just write a triple nested loop? – trincot Oct 14 '20 at 20:06
  • 1
    or a recursive function – JSmith Oct 14 '20 at 20:06
  • have you tried this (Iterate through Nested Objects) https://stackoverflow.com/questions/8085004/iterate-through-nested-javascript-objects#8085118 ? – pbachman Oct 14 '20 at 20:08
  • @Alberto A.M. I think marked duplicate answer should solve your problem. – Pankaj Parkar Oct 14 '20 at 20:08
  • Thanks everyone for your help, the main question is if it's posible to search only by a word that automatically search in all the fields. Imagine a general search, let's say that my array has like 80 different fields and apart of them nested arrays with other 40 different fields. Is there any possibility to evade searching and coding all the fields one by one on the filtering/searching? – Alberto A.M. Oct 14 '20 at 20:32

0 Answers0