export const imageTag = [
{链接:"https://images.pexels.com/photos/70069/pexels-photo-70069.jpeg?cs=srgb&dl=pexels-daniyal-ghanavati-70069.jpg&fm=jpg",id: 1,标题:“鸟类图像”,标签:“自然”,“鸟类”},{链接:"https://media.istockphoto.com/photos/renewable-energy-and-sustainable-development-picture-id1186330948?k=20&m=1186330948&s=612x612&w=0&h=5aNPCcQ8FcZraX44PEhb2mqcHkow2xMITJMHdh28xNg=",id: 2,标题:“自然1",标签:”自然“},{链接:"https://images.unsplash.com/photo-1538941214074-9b578e573632?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxleHBsb3JlLWZlZWR8Nnx8fGVufDB8fHx8&w=1000&q=80",id: 3,标题:河流图像”,标签:“自然”,“河流”},{链接:"https://images.pexels.com/photos/459198/pexels-photo-459198.jpeg?cs=srgb&dl=pexels-pixabay-459198.jpg&fm=jpg",id: 4,标题:“图像河流-自然”,标签:“自然”,“河流”},{ link:"https://images.pexels.com/photos/1001682/pexels-photo-1001682.jpeg?cs=srgb&dl=pexels-kellie-churchman-1001682.jpg&fm=jpg",id: 5,标题:"image12",标签:"sea“},{ link:"https://upload.wikimedia.org/wikipedia/commons/thumb/7/7d/Wildlife_at_Maasai_Mara_%28Lion%29.jpg/800px-Wildlife_at_Maasai_Mara_%28Lion%29.jpg",id: 6,标题:”动物1",标签:“动物”},{链接:"https://res.cloudinary.com/dk-find-out/image/upload/q_80,w_1920,f_auto/Animal_kingdom_nzwbda.jpg",id: 7,标题:“动物2",标签:”动物“},{链接:"https://image.shutterstock.com/image-photo/side-view-lion-walking-panthera-260nw-165448391.jpg",id: 8,标题:”狮子2",标签:“狮子”},{链接:"https://images.pexels.com/photos/1172253/pexels-photo-1172253.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500",id: 9,标题:“生活方式图像”,标签:“生活方式”,“河流”},{ link:"https://cdn.pixabay.com/photo/2017/08/30/01/05/milky-way-2695569__480.jpg",id: 10,标题:“银河1",标签:”银河“},{ link:"https://images.unsplash.com/photo-1453728013993-6d66e9c9123a?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8bGVuc3xlbnwwfHwwfHw%3D&w=1000&q=80",id: 11,标题:”透镜“,标签:”镜头“},{ link:"https://cdn.pixabay.com/photo/2015/04/19/08/32/marguerite-729510__480.jpg",id: 12,标题:”图像花“,标签:“自然”、“花”} ];
发布于 2022-09-02 11:52:42
这里有一种方法。
const data = [{ link: "https://images.pexels.com/photos/70069/pexels-photo-70069.jpeg?cs=srgb&dl=pexels-daniyal-ghanavati-70069.jpg&fm=jpg", id: 1, title: "Bird image", tags: ["nature", "bird"] }, { link: "https://media.istockphoto.com/photos/renewable-energy-and-sustainable-development-picture-id1186330948?k=20&m=1186330948&s=612x612&w=0&h=5aNPCcQ8FcZraX44PEhb2mqcHkow2xMITJMHdh28xNg=", id: 2, title: "nature 1", tags: ["nature"] }, { link: "https://images.unsplash.com/photo-1538941214074-9b578e573632?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxleHBsb3JlLWZlZWR8Nnx8fGVufDB8fHx8&w=1000&q=80", id: 3, title: "river image", tags: ["nature", "river"] }, { link: "https://images.pexels.com/photos/459198/pexels-photo-459198.jpeg?cs=srgb&dl=pexels-pixabay-459198.jpg&fm=jpg", id: 4, title: "image river-nature", tags: ["nature", "river"] }, { link: "https://images.pexels.com/photos/1001682/pexels-photo-1001682.jpeg?cs=srgb&dl=pexels-kellie-churchman-1001682.jpg&fm=jpg", id: 5, title: "image12", tags: ["sea"] }, { link: "https://upload.wikimedia.org/wikipedia/commons/thumb/7/7d/Wildlife_at_Maasai_Mara_%28Lion%29.jpg/800px-Wildlife_at_Maasai_Mara_%28Lion%29.jpg", id: 6, title: "Animal 1", tags: ["animal"] }, { link: "https://res.cloudinary.com/dk-find-out/image/upload/q_80,w_1920,f_auto/Animal_kingdom_nzwbda.jpg", id: 7, title: "Animal 2", tags: ["animal"] }, { link: "https://image.shutterstock.com/image-photo/side-view-lion-walking-panthera-260nw-165448391.jpg", id: 8, title: "lion 2", tags: ["lion"] }, { link: "https://images.pexels.com/photos/1172253/pexels-photo-1172253.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500", id: 9, title: "lifestyle image", tags: ["lifestyle", "river"] }, { link: "https://cdn.pixabay.com/photo/2017/08/30/01/05/milky-way-2695569__480.jpg", id: 10, title: "galaxy 1", tags: ["galaxy"] }, { link: "https://images.unsplash.com/photo-1453728013993-6d66e9c9123a?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8bGVuc3xlbnwwfHwwfHw%3D&w=1000&q=80", id: 11, title: "Lens", tags: ["lens"] }, { link: "https://cdn.pixabay.com/photo/2015/04/19/08/32/marguerite-729510__480.jpg", id: 12, title: "image flower", tags: ["nature", "flower"] } ]
const allTags = []
data.forEach(item => {
const {tags} = item
allTags.push(...tags)
})
const filtered = [...new Set(allTags)].sort()
console.log(filtered)
https://stackoverflow.com/questions/73581816
复制相似问题