javascript - slice dosent work in function js -


simple thing doing eloquentjs exercise. slice doesn't return right output array in functions parameter

console.log(swaparray([1, 2, 3, 4, 5, 6, 7]));  function swaparray(inserttab) {     console.log([0, 1, 2, 3, 4].slice(2, 4)); // work fine     inserttab.slice(2, 4); // nothing     return inserttab; } 

array.prototype.slice() doesn't mutate array called on, returns new array. assign return value inserttab , works fine:

console.log(swaparray([1, 2, 3, 4, 5, 6, 7]));    function swaparray(inserttab) {    console.log([0, 1, 2, 3, 4].slice(2, 4));    inserttab = inserttab.slice(2, 4);    return inserttab;  }


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -