Skip to content

Day404: 实现一个获取对象任意属性的方法?(字节) #407

@qappleh

Description

@qappleh
const getAttribute = (object /*目标对象*/,attribute /*目标属性*/, defaultValue /*默认值*/)

示例:
const obj = {a: {b: {c: 100}}, d:[{f: 'abc'}]};
getAttribute(obj, 'a.b.c', 0) === 100
getAttribute(obj, 'a.b.e', 'default') === 'default'
getAttribute(obj, 'd.0.f') === 'a.b.c'

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions