1. Home
  2. Computing & Technology
  3. JavaScript
photo of Stephen Chapman

Stephen's JavaScript Blog

By Stephen Chapman, About.com Guide to JavaScript since 2004

Array Average Value

Tuesday April 22, 2008
If we have an array of numbers in JavaScript, how can we determine the average?

While getting the maximum and minimum values from an array does not depend on the array contents being of any particular type, calculating the average depends on the content either being numbers or being able to be converted into numbers. Here's how to add a method to your arrays to allow the average value to be retrieved that will ignore any values in the array that can't be converted into a number.

Array Average Value

Comments

No comments yet. Leave a Comment

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Explore JavaScript

More from About.com

  1. Home
  2. Computing & Technology
  3. JavaScript

©2008 About.com, a part of The New York Times Company.

All rights reserved.