constgetKey=(array,key)=>array.map(a=>a[key]);constcountries=[{name:'France',capital:'Paris'},{name:'Spain',capital:'Madrid'},{name:'Italy',capital:'Rome'}]getKey(countries,'name')// even shorter
Very nice. I usually use the other one because that way itβs easier to chain with other array methods: .filter() an array, .map() some values out of its elements, .sort() the result, maybe run a .reduce() over it, all in the same chain.
If thatβs not the scenario, I like your solution better.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
How about this,
Very nice. I usually use the other one because that way itβs easier to chain with other array methods: .filter() an array, .map() some values out of its elements, .sort() the result, maybe run a .reduce() over it, all in the same chain.
If thatβs not the scenario, I like your solution better.