Double the numbers in JavaScript | Assignment Expert

Problem Statement:

We are given an array consisting of different data types in JavaScript. We need to create a new array that contains the datatypes of the previous array. If the data type is a number, then we do not need to convert that number to data type, we just need to multiply it by 2, which means just double it.

For example, [45, {1:'23', 2:'46', 3:'69'}, 'string', false] => [ 90, 'object', 'string', 'boolean' ]

Code for Double the numbers in JavaScript:

myArr = [45, {1:'23', 2:'46', 3:'69'}, 'string', false];
for(let i=0; i<myArr.length; i++){
  if(typeof myArr[i]==='number'){
    myArr[i] = myArr[i]*2;
    myArr[i] = typeof myArr[i]


Output for Double the numbers in JavaScript

Also Read:


Author: Harry

Hello friends, thanks for visiting my website. I am a Python programmer. I, with some other members, write blogs on this website based on Python and Programming. We are still in the growing phase that's why the website design is not so good and there are many other things that need to be corrected in this website but I hope all these things will happen someday. But, till then we will not stop ourselves from uploading more amazing articles. If you want to join us or have any queries, you can mail me at Thank you