This translation is incomplete. Please help translate this article from English.

המתודה ()unshift  מוסיפה אלמנט אחד או יותר לתחילת מערך ומחזירה את גודלו החדש של המערך. 

Syntax

arr.unshift(element1[, ...[, elementN]])

פרמטרים

elementN
אלמנטים להוספה לתחילת המערך.

ערך מוחזר

את ערך השדה length החדש של המערך עליו הופעלה המתודה.

תאור

המתודה unshift מכניסה את ערכי האלמנטים שקיבלה כפרמטר לתחילת אובייקט המערך. 

unshift is intentionally generic; this method can be called or applied 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.

Examples

var arr = [1, 2];

arr.unshift(0); // result of call is 3, the new array length
// arr is [0, 1, 2]

arr.unshift(-2, -1); // = 5
// arr is [-2, -1, 0, 1, 2]

arr.unshift([-3]);
// arr is [[-3], -2, -1, 0, 1, 2]

Specifications

Specification Status Comment
ECMAScript 3rd Edition (ECMA-262) Standard Initial definition. Implemented in JavaScript 1.2.
ECMAScript 5.1 (ECMA-262)
The definition of 'Array.prototype.unshift' in that specification.
Standard  
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Array.prototype.unshift' in that specification.
Standard  
ECMAScript Latest Draft (ECMA-262)
The definition of 'Array.prototype.unshift' in that specification.
Draft  

Browser compatibility

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
Basic supportChrome Full support 1Edge Full support YesFirefox Full support 1IE Full support 5.5Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes

Legend

Full support  
Full support

See also

Document Tags and Contributors

Contributors to this page: naomitayeb
Last updated by: naomitayeb,