add numbers to an array javascript code example
Example 1: adding numbers in an array javascript
console.log(
[].reduce((a, b) => a + b)
)
Example 2: how to push values in array
const animals = ['pigs', 'goats', 'sheep'];
const count = animals.push('cows');
console.log(count);
console.log(animals);
animals.push('chickens', 'cats', 'dogs');
console.log(animals);
Example 3: array.push
var vegetables = ['Capsicum',' Carrot','Cucumber','Onion'];
vegetables.push('Okra');
Example 4: add numbers from array nodejs
var values = [
'1',
'2'
]
var total = values[0] + values[1]
console.log(total);