Advertisement
dhshin

practice_7

Jun 26th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let empty_array = [];
  2. let array2 = [1, 1.5, false, "string", []];
  3. let array = [1,2,3,4];
  4.  
  5. console.log(empty_array); // []
  6. console.log(array2); // [1, 1.5, false, "string", []]
  7. console.log(array); // [1, 2, 3, 4]
  8. console.log(array[0]); // 1
  9. console.log(array.length); // 4
  10. console.log(array[4]); // undefined
  11.  
  12. array[2] = -1;
  13. array.push(5);
  14.  
  15. console.log(array); // [1, 2, -1, 4, 5]
  16. console.log(array.length); // 5
  17.  
  18. for(let i = 0; i < array.length; i++) {  
  19.     console.log(array[i]);
  20. }
  21. // 1, 2, -1, 4, 5 (on a separate line)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement