/    Sign up×
Community /Pin to ProfileBookmark

Hello,

I am currently working on building a library and having my functions(methods) within my library. I am having trouble find some code for JavaScript that can help me to do the following:

[B]Finding the total value of just the numbers in an array, even if some of the items are not numbers.[/B]

Anyone know what I am looking for?

Thanks so much!

Fred Williams

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERDec 15.2011 — If you are really interested in learning JS, you should attempt to do these simple functions yourself,

then ask for help when you can not make them work as desired.

<i>
</i>&lt;script type="text/javascript"&gt;
var arr = ['a',1,'b',2,'c',3,'d',4];

var sum = 0;
for (var i=0; i&lt;arr.length; i++) {
if (!isNaN(parseInt(arr[i]))) { sum += arr[i]; }
}
alert(sum);
&lt;/script&gt;


You will never get better without the work that goes with the knowledge.
×

Success!

Help @bybonline spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...