/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] How can I do the firs ten elems with a capitall letter in my array ?

I have an arry.

[CODE]
var spam = [‘january’, ‘february’, ‘march’, ‘april’, ‘may’, ‘june’, ‘julay’, ‘august’, ‘september’, ‘october’, ‘november’, ‘december’]
[/CODE]

How can I do it ?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERJul 29.2017 — Sometning like this?
<i>
</i>&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta charset="UTF-8" /&gt;
&lt;title&gt; HTML5 page &lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;script&gt;
var spam = ['january', 'february', 'march', 'april', 'may', 'june',
'julay', 'august', 'september', 'october', 'november', 'december'];
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
for (let i=0; i&lt;10; i++) {
spam[i] = capitalizeFirstLetter(spam[i]);
}
alert(spam.join('n'));
&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@mikefromruauthorJul 29.2017 — Thank you so much!
Copy linkTweet thisAlerts:
@rootJul 29.2017 — and a prototyped version Array.prototype.capitalize = function(){
for(var t=0; t&lt;this.length; t++)
this[t] = this[t].charAt(0).toUpperCase() + this[t].slice(1);
}

var monthNames = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'];
monthNames.capitalize();
console.log("Feb = "+monthNames[1]);
×

Success!

Help @mikefromru 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.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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