Arrays are mutable, Passed by sharing - Node.js Array

Node.js examples for Array:Array Operation

Description

Arrays are mutable, Passed by sharing

Demo Code


/**/*from   w  w  w . j  a  v a  2s.c om*/
 * Arrays are mutable
 * Passed by sharing
 */

function sum(numbers){
  numbers.push(numbers.reduce(function(prev, num){
    return prev + num;
  }, 0));
}

var numbersToAdd = [1, 2, 3];
sum(numbersToAdd);
console.log(numbersToAdd);

Related Tutorials