0

Say I have an Array of rows. Each row has an entity object. I want an Array of the entities. Is there a built-in or jquery array op that does this, but faster?

var nodes = [];
for( var inx = 0; inx < rows.length; inx++ ) {
    nodes.push( rows[ inx ].entity );
}
Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
ss ulrey
  • 298
  • 1
  • 8
  • 2
    Have you got performance problems with your existing code? – Matt May 22 '17 at 18:43
  • 1
    [`map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map?v=example), but I would echo @Matt's concern with prematurely optimizing your code. – Heretic Monkey May 22 '17 at 18:44
  • 1
    Why would jquery do it faster than native code... – juvian May 22 '17 at 18:44
  • Thanks all! The duplicate question is what i was searching for. To answer the questions, no I don't have a perf issue here yet, i was more just looking for a less clunky way to express it: just icing on the cake if it's more efficient i guess. FTR, map is the more syntactically succinct answer i was looking for, but it's actually slower: https://jsperf.com/extract-prop-from-object-array/ .... now i have to decide if i care :) – ss ulrey May 24 '17 at 13:54

0 Answers0