推送到索引处的对象数组

时间:2020-11-10 17:37:20

标签: javascript arrays

基本上,我有两个图像文件数组,一个带有缩略图,一个带有原始图像,缩略图的索引与它们各自数组中的原始图像相同。我想要一个包含每个文件路径的新数组。

所以基本上this.images看起来像这样[{path: x, originalPath: y}, {path: xx, originalPath: yy}, etc]

importAll(r) {
    let thumnailArray = r.keys();
    thumnailArray = thumnailArray.filter(s => !s.includes('_og'));
    thumnailArray.forEach(key => (
        this.images.push({
            path: r(key),
        })
    ));

    let originalArray = r.keys();
    originalArray = originalArray.filter(s => s.includes('_og'));

// this doesnt work, just adds to the end of the array...
    originalArray.forEach(key => (
        this.images.push({
            pathOriginal: r(key),
        })
    ));
},

但这不起作用:

originalArray.forEach((key, index) => (
    this.images[index].push({
        pathOriginal: r(key),
    })
));

我还能怎么做?

0 个答案:

没有答案