Easy way two double values in Array

Easy way two double values in Array

ยท

1 min read

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

ย