I have an object that looks something like this (except with a lot more props in each object):
const data: { [key: string]: any } = { Object1: { prop1: "Some random text", prop2: some number }, Object2: { prop1: "Some random text", prop2: some number } }
I have a function that creates Maps/Dictionaries from the object above:
const createMap = (data: { [key: number]: any }, propertyInData: any) => { const dataMap: { [key: number]: string } = {}; for (const eachObject in data) { if (Object.prototype.hasOwnProperty.call(eachObject, propertyInData)) { const category: number = data[eachObject].prop2; const eachPropertyValue = data[eachObject][propertyInData]; dataMap[category] = eachPropertyValue; return dataMap; }; } return { 0: "Wrong Key" } }
The problem is Object.prototype.hasOwnProperty.call(eachObject, propertyInData)
always comes out false. What Am I doing wrong?
https://stackoverflow.com/questions/67248826/object-prototype-hasownproperty-call-always-comes-out-false April 25, 2021 at 09:00AM
没有评论:
发表评论