简体   繁体   中英

How can I return the calculated value of an array?

I take the array length and summ

length = 8
summ = 7798

Can I return such an array using length and summ?

[5, 4, 96, 78, 1026, 5698, 789, 102]

The length of this array is 8, the sum of which is 7798

Very unclear what exactly you are looking for but this is roughly where you need to start lol

let array = [5, 4, 96, 78, 1026, 5698, 789, 
102]

let sum = array.reduce((a,b)=>a+b)
let length = array.length
console.log(sum) 
console.log(length)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM