将对象推送到Array会使参数为空

时间:2018-01-31 01:50:40

标签: javascript ecmascript-5

我试图解决合并两个对象数组的问题,所以我写了一个非常简单的函数

function mergeShowtimes(movies) {
    var existing_halls = [];

    return movies.reduce(function(acc, movie) {
        var movies_with_hallid,
            movies_seats;

        if (existing_halls.indexOf(movie.hallId) === -1) {
            movies_with_hallid = _.filter(movies, function(filter_movie) {
                return movie.hallId === filter_movie.hallId;
            });

            movies_seats = _.map(movies_with_hallid, 'seats');
            movie.seats = _.union.apply(this, movies_seats);
            acc.push(movie);
            existing_halls.push(movie.hallId);
        }

        return acc;
    }, []);
}

问题是,每当我检查moviemovie.seats的值时,字段'席位' movie中的movie.seats为空,但由于某种原因,acc.push(movie);不是

如果我删除pip is not an internal or external command nor is it a running program or batch file. ,一切都会按计划开始工作

我做错了什么?

感谢您的反馈!

0 个答案:

没有答案