JSFiddle - React, Tailwind, and code Playground

by kkdaily

JavaScript

const x = [1, 2, 3, 4]

// get the sum of all elements in the array

const sum = x.reduce((num, acc) => acc += num);

// multiply all nums by 2
const times2 = x.map((num) => num*2);



alert(times2)