enfoire

Untitled

Apr 18th, 2020
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>ARRAY YOO</title>
  5. <meta charset="utf-8">
  6. <script type="text/javascript">
  7. // colors -массив - хнарин 3 значения
  8. let colors = ['red', 'green', 'blue'];
  9. // numbers - массив - хранит 5 целых чисел
  10. let numbers = [1,2,3,4,5];
  11. // доступи к элементу массива по индексу
  12. console.log(colors[0]);
  13. // получить кол-во элементов в массиве (длина массива)
  14. //length - имя св-ва
  15. console.log(colors.length);
  16. console.log(numbers.length);
  17. // итерирование по элементам массива - используем цикл for
  18. console.log("all elements from colors");
  19. for(let i=0; i<colors.length; i=i+1){
  20. console.log(colors[i]);
  21. }
  22. // создание пустого массива
  23. let values = [];
  24. // наполнение массива элементами
  25. for(let i=0; i<colors.length; i=i+1){
  26. //values.push(i);
  27. values.push('VALUE'+ i);
  28. }
  29. for (let i=numbers.length-1; i>=0; i=i-1){
  30. console.log(numbers[i]);
  31. }
  32. </script>
  33.  
  34. </head>
  35. <body>
  36.  
  37. </body>
  38. </html>
Add Comment
Please, Sign In to add comment