From 218934fa2ed1c702a6d3923d2aa2cc6b43c48684 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:43:23 -0500 Subject: initial commit --- .../reference/global_objects/array/pop/index.html | 96 ++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 files/vi/web/javascript/reference/global_objects/array/pop/index.html (limited to 'files/vi/web/javascript/reference/global_objects/array/pop') diff --git a/files/vi/web/javascript/reference/global_objects/array/pop/index.html b/files/vi/web/javascript/reference/global_objects/array/pop/index.html new file mode 100644 index 0000000000..b5740406a5 --- /dev/null +++ b/files/vi/web/javascript/reference/global_objects/array/pop/index.html @@ -0,0 +1,96 @@ +--- +title: Array.prototype.pop() +slug: Web/JavaScript/Reference/Global_Objects/Array/pop +tags: + - JavaScript + - Mảng +translation_of: Web/JavaScript/Reference/Global_Objects/Array/pop +--- +
{{JSRef}}
+ +

Phương thức pop() xoá phần tử cuối cùng của một mảng và trả về phần tử đó. Phương thức này làm thay đổi độ dài của mảng.

+ +
{{EmbedInteractiveExample("pages/js/array-pop.html")}}
+ + + +

Cú pháp

+ +
arr.pop()
+ +

Giá trị trả về

+ +

Phần tử bị xoá từ mảng; {{jsxref("undefined")}} nếu mảng rỗng.

+ +

Mô tả

+ +

The pop method removes the last element from an array and returns that value to the caller.
+ Phương thức pop xoá phần tử cuối cùng của một mảng và trả về giá trị đó cho lời gọi.

+ +

pop is intentionally generic; this method can be {{jsxref("Function.call", "called", "", 1)}} ?or {{jsxref("Function.apply", "applied", "", 1)}} to objects resembling arrays. Objects which do not contain a length property reflecting the last in a series of consecutive, zero-based numerical properties may not behave in any meaningful manner.

+ +

Nếu bạn gọi pop() trên một mảng rỗng, nó trả về {{jsxref("undefined")}}.

+ +

Ví dụ

+ +

Xoá phần tử cuối cùng của một mảng

+ +

Đoạn mã sau tạo mảng myFish chứa 4 phần tử, sau đó xoá phần tử cuối cùng.

+ +
var myFish = ['angel', 'clown', 'mandarin', 'sturgeon'];
+
+var popped = myFish.pop();
+
+console.log(myFish); // ['angel', 'clown', 'mandarin' ]
+
+console.log(popped); // 'sturgeon'
+ +

Đặc tả

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Đặc tả?Trạng tháiGhi chú
{{SpecName('ES3')}}{{Spec2('ES3')}}Định nghĩa lần đầu. Cài đặt trong JavaScript 1.2.
{{SpecName('ES5.1', '#sec-15.4.4.6', 'Array.prototype.pop')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-array.prototype.pop', 'Array.prototype.pop')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-array.prototype.pop', 'Array.prototype.pop')}}{{Spec2('ESDraft')}} 
+ +

Tương thích trình duyệt

+ +
+ + +

{{Compat("javascript.builtins.Array.pop")}}

+
+ +

See also

+ + -- cgit v1.2.3-54-g00ecf