首页 > 解决方案 > 从单词中获取对象值

问题描述

假设我在 JS 文件中有这个对象:

const persons = [
    {
        name: 'John Doe',
        picture: 'https://images.google.com',
        year: '1971'
    },
    {
        name: 'Peter Doe',
        picture: 'https://images.google.com',
        year: '1981'
    }]

如何仅使用名称作为关键字来获取整个对象列表(名称、图片和年份)?就像如果名字是 John Doe 它只得到 John Doe 的名字、照片和年份?

标签: javascriptobject

解决方案


推荐阅读