filter-eg2

PHOTO EMBED

Wed Aug 17 2022 21:27:54 GMT+0000 (Coordinated Universal Time)

Saved by @vnmshenoy

//https://www.tutorialspoint.com/filter-array-based-on-another-array-in-javascript
const jsonResponse=[{
		"id": 1, "code": "Target0",
		"cost": 24

	}, {
		"id": 2, "code": "Target1",
		"cost": 23

	},
	{
		"id": 3,"code": "test",
		"cost": 23

	}, {
		"id": 4, "code": "Target2",
		"cost": 23

	},
  , {
    "id": 5, "code": "Maniac",
    "cost": 9

}
] 
const filterArray =['Target0','Target1','Target2']

const getObjectsFromjsonResponseBasedOnfilterArray =(arr1,arr2)=>{

const newArray=filterArray.filter(x=>{
let indexPos=x.indexOf(jsonResponse.code);
return indexPos>-1?jsonResponse[indexPos]:[]

})
    console.log(newArray);
}
content_copyCOPY

filter-eg2 is my code snippet in dev tools better way is to do via includes