In my current coding project, I am working with an array structured like this:
elements = [
{"year": 2010, "month": 11, "day":23}
{"year": 2009, "month": 10, "day":15}
{"year": 2009, "month": 10, "day":10} //added after my edit below
]
The task at hand is to extract specific columns from the array to create a new one that looks as follows:
newArray = [
{"year": 2010, "month": 11}
{"year": 2009, "month": 10}
]
I attempted to solve this using .map(), but unfortunately encountered some issues:
const newArray = [];
newArray.map({
year: items.year,
month: items.month
});
AFTER CODE EDIT
After implementing the suggestions provided by others, it dawned on me that I forgot to specify that I also require the result to be unique. As I focus solely on the year and month values now, duplicate rows are appearing in the output.