Change array values to lowercase or uppercase in jQuery

September 21, 2013 | 3105 views | Comments

Loop through an array to convert it's values to lowercase or uppercase using the $.each() function of jQuery. Call the toLowerCase() function to make all letters small, and to capitalize all letters, use toUpperCase().

For example.

Make all values of a given string small letters.

var theArray = ["The","Quick","Brown","Fox"];
$.each(theArray,function(index,item){
	theArray[index] = item.toLowerCase();
});
$.each(theArray,function(index,item){
	console.log(item);
});

//result
/*
the
quick
brown
fox
*/

Capitalize all letters of all values of a given array.

var theArray = ["The","Quick","Brown","Fox"];
$.each(theArray,function(index,item){
	theArray[index] = item.toUpperCase();
});
$.each(theArray,function(index,item){
	console.log(item);
});

//result
/*
The
QUICK
BROWN
FOX
*/

 

Related Tutorials


Must Read