tailieunhanh - Học JavaScript qua ví dụ part 26

Phương pháp Array Bởi vì mảng là một đối tượng trong JavaScript, nó có các đặc tính để mô tả nó và phương pháp để thao tác nó. Các tài sản dài của một mảng được sử dụng trong ví dụ trước để xác định kích thước của một mảng. Bây giờ chúng tôi sẽ xem xét các phương pháp cho phép bạn thao tác mảng như là thêm một nguyên tố mới vào đầu hoặc cuối của một mảng, loại bỏ một yếu tố từ cuối mảng, ngược lại một mảng, và như vậy. . | Array Methods 227 Figure An associative array one key associated with more than one value. Array Methods Because an array is an object in JavaScript it has properties to describe it and methods to manipulate it. The length property of an array was used in previous examples to determine the size of an array. Now we will look at methods that allow you to manipulate arrays such as adding a new element at the beginning or end of an array removing an element from the end of an array reversing an array and so on. JavaScript provides a whole set of methods for doing all of these things and more see Table . Table Array Methods Method What It Does concat Concatenates elements from one array to another array. join Joins the elements of an array by a separator to form a string. pop Removes and returns the last element of an array. push Adds elements to the end of an array. reverse Reverses the order of the elements in an array. shift Removes and returns the first element of an array. slice Creates a new array from elements of an existing array. sort Sorts an array alphabetically or numerically. splice Removes and or replaces elements of an array. toLocaleString Returns a string representation of the array in local format. toString Returns a string representation of the array. unshift Adds elements to the beginning of an array. From the Library of 228 Chapter 9 JavaScript Core Objects The concat Method. The concatO method concatenates the elements passed as arguments onto an existing array JavaScript returning a new concatenated list. The method does not change the existing array in place. You must assign results to either an existing array or a new one. FORMAT newArray new elements EXAMPLE names green blue EXAMPLE html head title Array concat methods title head body script type text javascript 1 var names1 new Array Dan Liz Jody 2 var names2 new Array Tom Suzanne b First array namesl br .

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã 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.