根据箭头函数获取对象属性
get object attributes based upon arrow function
// Sample object:
const abc = {
a: 'A',
b: 'B',
c: 'C'
}
// Sample Arrow function
const xyz = (item) => item.a
假设对象和箭头函数是分开定义的,这个箭头函数如何用于从对象中检索值?
使用 abc
对象作为参数调用 xyz
函数,您将得到 abc.a
属性 作为 return 值。
示例:
console.log(xyz(abc))
// Sample object:
const abc = {
a: 'A',
b: 'B',
c: 'C'
}
// Sample Arrow function
const xyz = (item) => item.a
假设对象和箭头函数是分开定义的,这个箭头函数如何用于从对象中检索值?
使用 abc
对象作为参数调用 xyz
函数,您将得到 abc.a
属性 作为 return 值。
示例:
console.log(xyz(abc))