this question has answer here:
sorry if title confusing.
i have object called question, contains property called brokenup. have randomly generated number. now, if number had 3 digits, want program add something. instance:
var arr = [400, 40, 2]; //really 442 broken up. var n= arr.length;
now main problem here:
question.brokenup = arr[0] + arr[1] + arr[2];
how can make line above work value?
what if had 4 digits? how can make arr[0]... arr[4] , on?
you use reduce this:
var arr = [1,2,3,4] // whatever length; var brokenup = arr.reduce(function(a, b) {return + b;}, ''); // empty string here