I have an array of objects and each object has around 5 properties and respective values. I would like to iterate through each object in the array and pick only two properties from it and rebuild the object and the array.
For example:
let resArray = [
{"name": "Aaron", "id": 123, "sex": "male", "country": "usa"},
{"name": "Bert", "id": 456, "sex": "male", "country": "usa"},
{"name": "Brenda", "id": 657, "sex": "female", "country": "canada"},
{"name": "Chris", "id": 856, "sex": "male", "country": "usa"},
{"name": "Angela", "id": 113, "sex": "female", "country": "columbia"},
{"name": "Maria", "id": 569, "sex": "female", "country": "mexico"}];
I want to remove the "country" and the "sex" properties from the objects and retain the "name" and "id" properties and rebuild the array. i.e., the output should be as follows:
let outArray = [
{"name": "Aaron", "id": 123},
{"name": "Bert", "id": 456},
{"name": "Brenda", "id": 657},
{"name": "Chris", "id": 856},
{"name": "Angela", "id": 113},
{"name": "Maria", "id": 569}];
As of now, I am just using the resArray and iterating through the whole array and getting whatever values I want. But I just think I can minimize the object so that it will be clear of the clutter.
Could anyone help me out with it? Thank you.