Javascript Object Array get attributes via for loop

Description

Javascript Object Array get attributes via for loop

//For Loop//from w  w  w  .  j a  va  2  s  . c o  m

function getStockSymbols(stocks){
  var symbols = [],
      counter,
      stock;
  
  for(counter=0; counter<stocks.length; counter++){
      stock = stocks[counter];
      symbols.push(stock.symbol);
  }
  return symbols;
}


var symbols = getStockSymbols([
  { symbol: "XFX", price: 240.22, volume: 23432 },
  { symbol: "TNZ", price: 332.19, volume: 234 },
  { symbol: "JXJ", price: 120.22, volume: 5323 },
]);

console.log(symbols);



PreviousNext

Related