获取JSON字符串数据

我需要获取的title,interval但是我的函数返回了undefined。


功能


filterByCategories () {

      return _.orderBy(this.meetups.filter(item => {

        console.log('title: ' + JSON.stringify(item.interval.title, null, 4))

JSON(的内容this.meetups):


[

    {

        "id": "-12345",

        "title": "abcds",

        "description": "Hello3",

        "date": "2023-12-29",

        "location": {

            "color": "grey darken-2",

            "icon": "not_interested",

            "id": "none",

            "title": ""

        },

        "creatorId": "abcd1234",

        "time": "24:00",

        "color": {

            "color": "red darken-2",

            "id": "06",

            "title": "Ret"

        },

        "interval": {

            "color": "green darken-2",

            "icon": "local_activity",

            "title": "Weekly",

            "value": 3

        },

        "statusType": false,

        "pause": false,

        "pushNotification": false

    }

]

如何阅读间隔标题?


米琪卡哇伊
浏览 254回答 2
2回答

莫回无

尝试执行此操作,如果中有多个对象meetups,则可以使用Array.map遍历对象数组,并在其中打印出该title属性的值interval。this.meetups.map(obj => {  console.log(`title: ${obj['interval']['title']}`);});还是简单地说,如果其中只有1个对象meetups?this.meetups[0]['interval']['title']演示:const meetups =[{"id":"-12345","title":"abcds","description":"Hello3","date":"2023-12-29","location":{"color":"grey darken-2","icon":"not_interested","id":"none","title":""},"creatorId":"abcd1234","time":"24:00","color":{"color":"red darken-2","id":"06","title":"Ret"},"interval":{"color":"green darken-2","icon":"local_activity","title":"Weekly","value":3},"statusType":false,"pause":false,"pushNotification":false}];meetups.map(obj => {  console.log(`title: ${obj['interval']['title']}`);});关于您在问题中提供的代码,我不确定您为什么要使用Array.filter(),因为它的作用是基于您提供的回调函数返回一个新数组filter()。此外,使用JSON.stringify()对其进行字符串化处理会将该数组转换为字符串,这违背了访问对象数组中的值的目的。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript