Học php, mysql và javascript - p 38

Ba báo cáo chính của kịch bản này được thể hiện trong đậm. Kịch bản đầu tiên tạo ra một mảng gọi là thể thao với ba yếu tố và sau đó đẩy một yếu tố thứ tư vào mảng. Sau đó nó hiện ra rằng phần tử quay trở lại. | Example 16-13. Using the push and pop methods script sports Football Tennis Baseball Start sports br Hockey After Push sports br removed After Pop sports br Removed removed br script The three main statements of this script are shown in bold type. First the script creates an array called sports with three elements and then pushes a fourth element into the array. After that it pops that element back off. In the process the various current values are displayed using . The script outputs the following Start Football Tennis Baseball After Push Football Tennis Baseball Hockey After Pop Football Tennis Baseball Removed Hockey The push and pop functions are useful in situations where you need to divert from some activity to do another then return as in Example 16-14. Example 16-14. Using push and pop inside and outside of a loop script numbers for j 0 j 3 j j Pushed j br Perform some other activity here br Popped br Popped br Popped br script The output from this example is Pushed 0 Pushed 1 Pushed 2 Popped 2 Popped 1 Popped 0 JavaScript Arrays 351 Using reverse The reverse method simply reverses the order of all elements in an array. Example 16-15 shows this in action. Example 16-15. Using the reverse method script sports Football Tennis Baseball Hockey sports script The original array is modified and the output from this script is Hockey Baseball Tennis Football sort With the sort method you can place all the elements of an array in alphabetical or other order depending upon the parameters used. Example 16-16 shows four types of sort. Example 16-16. Using the sort method script Alphabetical sort sports Football Tennis Baseball Hockey sports br Reverse alphabetical sort sports Football Tennis .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
8    545    1    13-06-2024
77    385    9    13-06-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.