使用节点js过滤对象值

filter object value using node js

有什么方法可以过滤对象中存在的值

[
{
id: "1",
name:"animal_image.jpg"
},
{
id: "2",
name:"fish_image.jpg"
},
{
id: "3",
name:"animal_doc.txt"
},{
id: "4",
name:"fish_doc.txt"
},
{
id: "4",
name:"flower_petals.jpg"
},
{
id: "5",
name:"plant_roots.jpg"
},
{
id: "6",
name:"human_image.jpg"
},
]

我想过滤所有包含_image.jpg的名称所以输出看起来像这样

output= 
[ "human_image.jpg",
  "anima_image.jpg",
  "fish_image.jpg"
]

filter & map

const output = arr
  .filter(x => x.name.endsWith('_image.jpg'))
  .map(x => x.name);

在此代码段中,filtredData 是一个对象数组,其中名称包含 _image.jpg,而 output 只是一个包含 _image.jpg[=15= 的名称数组]

const data = [
    {
        id: "1",
        name: "animal_image.jpg"
    },
    {
        id: "2",
        name: "fish_image.jpg"
    },
    {
        id: "3",
        name: "animal_doc.txt"
    }, {
        id: "4",
        name: "fish_doc.txt"
    },
    {
        id: "4",
        name: "flower_petals.jpg"
    },
    {
        id: "5",
        name: "plant_roots.jpg"
    },
    {
        id: "6",
        name: "human_image.jpg"
    },
]

const filtredData = data.filter(el => el.name.includes("_image.jpg"));

console.log(filtredData);

const output = filtredData.map(el => el.name);

console.log(output);