I want to return the key of the object where it's ContractID value equals 10. So in this example I want to return 0.
{
0 : {ContractID: 10, Name: "dog"}
1 : {ContractID: 20, Name: "bar"}
2 : {ContractID: 30, Name: "foo"}
}
I've tried using the filter method but it doesn't work how I'd have wanted.
var id = objname.filter(p => p.ContractID == 10);
This instead returns the array, not the key. How can I return the key?
const keys = Object.keys(objname).filter(key => objname[key].ContractId === 10)