Sunday, May 31, 2015

The Reduce Method of a Javascript Array

  • I've seen alot of confusing Youtube videos on this subject, but
  • but here is an easy way of using the reduce method of a javascript array.  
  • var colors=
  • ["red", "blue", "yellow", "black", "purple", "chartreuse"];
  • var newcolors= colors.reduce(function(k,j){return k+ " and " +j},colors[1]);
  • "blue and red and blue and yellow and black and purple and chartreuse"

No comments:

Post a Comment