Javascript Object Array get attributes via forEach method

Description

Javascript Object Array get attributes via forEach method

// For Each//w  w w  .  ja v a  2 s.c o m
function getStockSymbols(stocks){
  var symbols = [];
  
  
  stocks.forEach(function(stock){
    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