Skip to content

All topics  /  Node.js

How to Convert Array to Uppercase in Node JS?

Node.js ·

Hi friends,

In this example, I will show you how to convert an array to uppercase in node js. it's a simple example of convert an array to uppercase in node.js. This post will give you a simple example of node js array to uppercase. This tutorial will give you a simple example of the array to uppercase node.js. So, let's follow a few step to create an example of get array in uppercase node js.

This example is how to convert an array to uppercase in node js. I give you two examples of convert an array to uppercase in node js. I will use this example in the toUpperCase function and split function.

let's see below a simple example with output:

Install Node JS


This step is not required; however, if you have not created the node js app, then you may go ahead and execute the below command:

mkdir my-app
cd my-app

 
npm init

Example: 1

index.js

//create array list
myArray = ["banana","apple","orange","lemon"];
//create another variable (newArr) which would store your "loop through myArray"
newArr = myArray.map(arr => arr.toUpperCase())
console.log(newArr)

Output:

[ 'BANANA', 'APPLE', 'ORANGE', 'LEMON' ]

Example: 2

index.js

//create array list
myArray = ["piyush","pratik","mehul","keval","nikhil","kashyap","hardik","vimal","harshad"];
//convert to lowercase to UpperCase
strArray = String(myArray).toUpperCase().split(",");
console.log(strArray)

Output:

[
  'PIYUSH',  'PRATIK',
  'MEHUL',   'KEVAL',
  'NIKHIL',  'KASHYAP',
  'HARDIK',  'VIMAL',
  'HARSHAD'
]