Home:ALL Converter>filter an array based on values of another array in typescript

filter an array based on values of another array in typescript

Ask Time:2021-12-20T18:48:27         Author:salma

Json Formatter

if I have an array looking as the following:

names: [{
  value: 'recordedData',
  desc: 'Data'
} {
  value: 'recordedNumbers',
  desc: 'numbers'
} {
  value: 'recordedNames',
  desc: 'names'
}]

and another array looking as the following:

displayed: [{
  value: 'data',
  desc: 'Data'
} {
  value: 'numbers',
  desc: 'numbers'
}]

I want to filter the first array based on the second array so I would have the following resulted array :

DisplayedNames: [{
  value: 'recordedData',
  desc: 'Data'
} {
  value: 'recordedNumbers',
  desc: 'numbers'
}]

Author:salma,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/70420655/filter-an-array-based-on-values-of-another-array-in-typescript
yy