[JS practice] Pluck function(读取数组中相同属性的项目)

Title :
Pluck (读取数组中相同属性的项目)


Implement pluck, which takes an array of objects and a property name, and returns an array containing the named property of each object.

我用到了循环,不过似乎还有更简单的方法哦 🙂

For example:

pluck([{a:1}, {a:2}], 'a') // -> [1,2]

If an object is missing the property, you should just leave it as undefined in the output array.

Continue reading


Javascript – get size of an object

In javascript, we don’t have a method who could get the size of an object directly. But we could consider it as an array, and get the size of the array.

Method 1 :

size1 = Object.keys(object).length

Method 2 :

size2 = Object.values(object).length

Method 3 :

We could wirte a function, I will give it later