hey campers! getting confused again trying stuff out in a pad cause sometimes its nice to go away from the questions and just play with stuff to understand how its working below is my code and basicly im wondering if what im trying to figure out is possible or if im misunderstanding something else
let obj = [{name:"name",
age:20,},
{name:"bill",
age:16,},
{age:20}
]
let com = {name:"bill"}
let filterArr = obj.filter( (x) => x.hasOwnProperty(["name"]) ) //this works and only shows the entires with a name feild, but i want to replace ["name"] with the com variable many thanks
//this works and only shows the entires with a name feild, but i want to replace ["name"] with the com variable many thanks
ah sorry if i badly explained what i want to do is be able to use a placeholder in the working code above instead of a known feild for instance the code above only prints into console the objects with the name feild and not the the which is only age. i want to replace the ([“name”]) to ([com]) so it will filter based on a variable or arugment/parameter.
to be honest i have diffeculty going tho a thinking process to access objects in arrays and when its doing something with an object to an object in an array i just fall flat
ok i figured it out, there is an Object.keys method which you can call on objects to put each key into an array only took 2days of confusion online wheyy i suck lol