Skip to main content

Command Palette

Search for a command to run...

Easy way two double values in Array

Published
β€’1 min read
Easy way two double values in Array
D

I am 17 years old and a young passionate and self-taught frontend web developer and have an intention to become a successful developer. I usually write about JavaScript and Web Development and share some tips in the articles.

Welcome πŸ‘‹,

In this article, I will be showing an Easy way to double values in the array

Method - 1

const numbers = [3, 5, 7, 9, 11, 13]
const doubled =[]
for(let i = 0; i < numbers.length; i++){
    doubled.push(numbers[i]*2)
}
console.log(doubled)

Check out Demo

Method - 2

const numbers = [3, 5, 7, 9, 11, 13]
const doubled = numbers
  .filter(n => n !== 0)
  .map(n => n * 2);
console.log(doubled)

Feel free to share ideas in the comments...


Follow me at Twitter - @codewithsnowbit Subscribe at YouTube - codewithsnowbit

40 views

More from this blog

D

Dhairya Shah

119 posts