Is there a way to only show selected property in a json object based on a array

前端 未结 2 1547
北恋
北恋 2021-01-19 07:50

I have the following object

calendarLists = [
    {Title: titel1, Color:blue, number:1}
    {Title: titel2, Color:green, number:2}]
    {Title: titel3, Color         


        
2条回答
  •  盖世英雄少女心
    2021-01-19 08:30

    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);
    

提交回复
热议问题