Advertisement
karlakmkj

Arrays and Functions

Dec 9th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //In both cases, the change to the array was maintained outside of the function
  2.  
  3. const concept = ['arrays', 'can', 'be', 'mutated'];
  4.  
  5. function changeArr(arr){
  6.   arr[3] = 'MUTATED';
  7. }
  8.  
  9. changeArr(concept);
  10. console.log(concept); //Output will be [ 'arrays', 'can', 'be', 'MUTATED' ]
  11.  
  12. function removeElement(newArr){  
  13.   newArr.pop();
  14. }
  15.  
  16. removeElement(concept);
  17. console.log(concept);  //Output will be [ 'arrays', 'can', 'be' ]
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement