I have an array of JavaScript objects, smth like this:
const employe = [{
id: 1,
age: 22,
sex: 'Male',
},
{
id: 2,
age: 23,
sex: 'Female',
},
{
id: 3,
age: 33,
sex: 'Male',
}
]
I want to sort them based on object key:
for example: function sort(age, sex)
and i get array:
[22, 23, 33, 'male', 'female', 'male']
I try to do smth like this:
function filterArr(arr, category) {
let res = {};
for (let key in arr) {
if (arr[key].category == category)
res[key] = arr[key];
}
return res;
}