aboutsummaryrefslogtreecommitdiff
path: root/files/tr/web/javascript/reference/global_objects/array/pop/index.html
blob: 649cb88921b6283e8cf8074c9524fccf22ed8322 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
---
title: Array.prototype.pop()
slug: Web/JavaScript/Reference/Global_Objects/Array/pop
translation_of: Web/JavaScript/Reference/Global_Objects/Array/pop
---
<div>{{JSRef}}</div>

<p><code><strong>pop()</strong></code> yöntemi, bir dizideki <strong>son</strong> öğeyi kaldırır ve o öğeyi döndürür. Bu yöntem dizinin uzunluğunu değiştirir.</p>



<div>{{EmbedInteractiveExample("pages/js/array-pop.html")}}</div>



<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox"><var>arr</var>.pop()</pre>

<h3 id="Return_value">Return value</h3>

<p>The removed element from the array; {{jsxref("undefined")}} if the array is empty.</p>

<h2 id="Description">Description</h2>

<p>The <code>pop</code> method removes the last element from an array and returns that value to the caller.</p>

<p><code>pop</code> 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 <code>length</code> property reflecting the last in a series of consecutive, zero-based numerical properties may not behave in any meaningful manner.</p>

<p>If you call <code>pop()</code> on an empty array, it returns {{jsxref("undefined")}}.</p>

<p>{{jsxref("Array.prototype.shift()")}} has similar behavior to <code>pop</code>, but applied to the first element in an array.</p>

<h2 id="Examples">Examples</h2>

<h3 id="Removing_the_last_element_of_an_array">Removing the last element of an array</h3>

<p>The following code creates the <code>myFish</code> array containing four elements, then removes its last element.</p>

<pre class="brush: js">var myFish = ['angel', 'clown', 'mandarin', 'sturgeon'];

var popped = myFish.pop();

console.log(myFish); // ['angel', 'clown', 'mandarin' ]

console.log(popped); // 'sturgeon'</pre>



<h3 id="Using_apply_or_call_on_array-like_objects">Using apply( ) or call ( ) on array-like objects</h3>

<p>The following code creates the <code>myFish</code> array-like object containing four elements and a length parameter, then removes its last element and decrements the length parameter.</p>

<pre class="brush: js">var myFish = {0:'angel', 1:'clown', 2:'mandarin', 3:'sturgeon', length: 4};

var popped = Array.prototype.pop.call(myFish); //same syntax for using apply( )

console.log(myFish); // {0:'angel', 1:'clown', 2:'mandarin', length: 3}

console.log(popped); // 'sturgeon'
</pre>



<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('ES3')}}</td>
   <td>{{Spec2('ES3')}}</td>
   <td>Initial definition. Implemented in JavaScript 1.2.</td>
  </tr>
  <tr>
   <td>{{SpecName('ES5.1', '#sec-15.4.4.6', 'Array.prototype.pop')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-array.prototype.pop', 'Array.prototype.pop')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-array.prototype.pop', 'Array.prototype.pop')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td></td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<div>


<p>{{Compat("javascript.builtins.Array.pop")}}</p>
</div>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{jsxref("Array.prototype.push()")}}</li>
 <li>{{jsxref("Array.prototype.shift()")}}</li>
 <li>{{jsxref("Array.prototype.unshift()")}}</li>
 <li>{{jsxref("Array.prototype.concat()")}}</li>
 <li>{{jsxref("Array.prototype.splice()")}}</li>
</ul>

<div id="gtx-trans" style="position: absolute; left: 79px; top: 355px;">
<div class="gtx-trans-icon"></div>
</div>