sum of all elements in array python code example

Example 1: sum of all numbers in an array javascript

const arrSum = arr => arr.reduce((a,b) => a + b, 0)

Example 2: addition of array in python with input

#Python program to add all the array elements using the built-in function
lst = []
num = int(input("Enter the size of the array: "))
print("Enter array elements: ")
for n in range(num):
  numbers = int(input())
  lst.append(numbers)
print("Sum:", sum(lst))

Example 3: return last two values of array in javascript

arr.slice(Math.max(arr.length - 5, 1))