This question is dated, but I'm posting my response hoping it will help others.
This is what you need:
objectArray
.filter((obj) => obj.key === key)
.map((item) => {
return item.value;
}
);
Below is the fully functional code:
const objectArray = [
{ key: '1', value: '12321' },
{ key: '2', value: 'asdfas' },];
/* This function will return the value you're looking for. */
function getObjectValueById(key: string) {
return objectArray
.filter((obj) => obj.key === key)
.map((item) => {
return item.value;
}
);
}
Because your key is a string, I am using key: string in the function's argument. If your key is a number, then you can modify the function argument to key: number, and rest of the code will still work.