As I delve into learning TypeScript, one question that arises is the most efficient method for subsetting an object based on the property values from another array.
Consider the following object and array:
const Aobject =
{
"cities": [
{
"id": "city_id1",
"name": "NY"
},
{
"id": "city_id2",
"name": "BOS"
},
{
"id": "city_id3",
"name": "SF"
},
{
"id": "city_id4",
"name": "LA"
}
]
}
const Aarray = ["city_id2", "city_id3"]
The expected output in array form would be:
[
{
"id": "city_id2",
"name": "BOS"
},
{
"id": "city_id3",
"name": "SF"
}
]