[Vuejs]-I use filter return array get eslint error

4👍

const filter = state.playListSetData.filter(item => {
                        // 若兩相符合,抓播放設定底下的其他資料
                        if (item.uuid === payload[i].playerList[j].uuid) {
                            return item;
                        }
                        return false;
                    });

if you return something for some cases, your linter wants you to explicitly return something for all cases. return undefined I guess is closer to what it was doing before but it is all the same for filter

or simply

const filter = state.playListSetData.filter(item => {
                        // 若兩相符合,抓播放設定底下的其他資料
                        return item.uuid === payload[i].playerList[j].uuid;
                    });

filter only cares if it is truthy, and doesn’t really use the value of item, and since you are accessing properties, it looks like it is always truthy, so just return true.

Leave a comment