I have the following object
calendarLists = [
{Title: titel1, Color:blue, number:1}
{Title: titel2, Color:green, number:2}]
{Title: titel3, Color
You could map the wanted properties as objects, collect them to a single object and mapp all objects for a new array.
var calendarLists = [
{ Title: 'titel1', Color: 'blue', number: 1 },
{ Title: 'titel2', Color: 'green', number: 2 },
{ Title: 'titel3', Color: 'red', number: 3 }
],
keys = ['Title', 'number'],
result = calendarLists.map(o => Object.assign(...keys.map(k => ({ [k]: o[k] }))));
console.log(result);
The same with a destructuring assignment and short hand properties.
var calendarLists = [
{ Title: 'titel1', Color: 'blue', number: 1 },
{ Title: 'titel2', Color: 'green', number: 2 },
{ Title: 'titel3', Color: 'red', number: 3 }
],
result = calendarLists.map(({ Title, number }) => ({ Title, number }));
console.log(result);
Your calendarLists has syntax error. You can map this array and filter wanted properties.
calendarLists = [{
Title: 'titel1',
Color: 'blue',
number: 1
},
{
Title: 'titel2',
Color: 'green',
number: 2
},
{
Title: 'titel3',
Color: 'red',
number: 3
}
];
result = calendarLists.map(
calendarList => {
return {
Title: calendarList.Title,
number: calendarList.number
}
}
);
console.log(result);