Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Lelana villa
Added: Mar 23, 2018 7:45 PM
Views: 1015
Tags: no tags
  1. var arr = [true, 2, 3, "4"];
  2. new_array = arr.concat(5, 6, 7)
  3. console.log(new_array);         // [true, 2, 3, "4", 5, 6, 7]
  4.  
  5. new_array = arr.slice(0, 2);
  6. console.log(new_array);         // [true, 2]
  7.  
  8. console.log(arr);               // arr not changed - [true, 2, 3, "4"]
  9. arr.splice(0, 1, 1); // I replace the first item with 1
  10. console.log(arr);                // [1, 2, 3, "4"]