the Internet Windows Android

Push javascript examples. Arrays

Their push () Method Adds One Or More Elements To the New Length of the Array.

The Source For This Interactive Example IS Stored in A Github Repository. If you "d Like to Contribute to the Interactive Examples Project, Please Clone https://github.com/mdn/Interactive-examples and Send US A Pull Request.

Syntax

ARR .PUSH (Element1 [, ... [, Elementn]])

Parameters.

Element. N. The Element (s) to Add to the End of the Array.

Return Value.

Examples.

Adding Elements To An Array

The Following Code Creates The Sports Array Containing Two Elements, Then Appends Two Elements to IT. The Total Variable CONTAINS THE NEW LENGTH OF THE ARRAY.

Let Sports \u003d ["Soccer", "Baseball"] Let Total \u003d Sports.push ("Football", "Swimming") Console.log (Sports) // ["Soccer", "Baseball", "Football", "Swimming "] Console.log (Total) // 4

Merging Two Arrays.

This example uses Apply () to Push All Elements from a Second Array.

Do. not. Use This Method If The Second Array (Morevegs in the example) Is Very Large, Because The Maximum Number of Parameters That One Function Can Take Is Limited in Practice. See Apply () for more details.

Let Vegetables \u003d ["Parsnip", "Potato"] Let Morevegs \u003d ["Celery", "Beetroot"] // Merge The Second Array Into The First One // Equivalent to Vegetables.Push ("Celery", "Beetroot") Array.prototype.push.apply (Vegetables, Morevegs) Console.log (Vegetables) // ["Parsnip", "Potato", "Celery", "beetroot"]

USING AN OBJECT IN AN ARRAY-LIKE FASHION

AS Mentioned Above, Push Is Intentionally Generic, and We Can Use That To Our Advantage. Array.prototype.push Can Work on An Object Just Fine, As This Example Shows.

Note That We Don "T Create An Array to Store A Collection of Objects. Instead, We Store The Collection on the Object ItSelf and Use Call on Array.prototype.push to Treick The Method Into Thinking We Are Dealing With An Array-and It Just Works, Thanks to the Way JavaScript Allows US to Establish The Execution Context However We Please.

Let OBJ \u003d (Length: 0, Addlem: Function Addlem (Elem) (// OBJ.LENGTH IS Automatically Incremented // Every Time An Element IS Added. .Push.call (this, elem))) // Let "S Add Some Empty Objects Just to Illustrate. Obj.addelem (()) Obj.addelem (()) Console.log (Obj.Length) // → 2

Note That Although Obj Is Not An Array, The Method Push SuccessFully Incremented OBJ "S Length Property Just Like If We Were Dealing WE WERE DAILING WITH AN ACTUAL ARRAY.

Specifications.

Specification Status. Comment
ECMAScript 3RD Edition (ECMA-262) Standard. Initial Definition. IMPLEMENTED IN JAVASCRIPT 1.2.
ECMASCRIPT 5.1 (ECMA-262)
Standard.
ECMASCRIPT 2015 (6th Edition, ECMA-262)
The Definition of "Array.Prototype.push" in that specification.
Standard.
ECMAScript Latest Draft (ECMA-262)
The Definition of "Array.Prototype.push" in that specification.
DRAFT.

Browser Compatibility

The Compatibility Table in this page is Generated from Structured Data. If you "d Like to Contribute to the Data, Please check out https://github.com/mdn/browser-compat-data and send us a Pull Request.

Update Compatibility Data On GitHub

Desktop.MobileServer
Chrome.Edge.Firefox.Internet Explorer.Opera.Safari.Android WebView.Chrome for AndroidFirefox for AndroidOpera for AndroidSafari On ios.Samsung internetNode.js.
Push.Chrome Full Support 1Edge Full Support 12Firefox Full Support 1IE Full Support 5.5Opera Full Support YesSafari Full Support 1WebView Android Full Support YesChrome Android Full Support 18Firefox Android Full Support 4Opera Android Full Support YesSafari iOS Full Support 1SAMSUNG Internet Android Full Support Yesnodejs Full Support Yes

Method push () Adds one or more elements to the end of the array and returns a new array length.

Syntax

ARR .PUSH (Element1 [, ... [, Elementn]])

parameters

Element. N. Elements to add to the end of the array.

Return value

var vegetables \u003d ["Parsnip", "Potato"]; var morevegs \u003d ["Celery", "beetroot"]; // Merge The Second Array Into The First One // Equivalent to Vegetables.push ("Celery", "Beetroot"); Array.prototype.push.apply (Vegetables, Morevegs); Console.log (Vegetables); // ["Parsnip", "Potato", "Celery", "beetroot"]

Using an object in the form of an array

As mentioned above, PUSH is deliberately general, and we can use it in our interests. Array.Prototype.Push can work with the object just excellent, as it shows this example. Please note: we do not create an array for storing the collection of objects. Instead, we store the collection on the object itself and use Call Array.Prototype.Push to fool the method, thinking that we are dealing with an array, and it just works, due to the fact that JavaScript allows us to establish the execution context, however we please.

Var OBJ \u003d (Length: 0, AddElem: Function Addlem (ELEM) (// OBJ.Length Is Automatically Incremented // Every Time An Element Is Added. .Push.call (this, Elem);)); // Let "S Add Some Empty Objects Just to Illustrate. Obj.addelem (()); obj.addelem (()); Console.log (Obj.Length); // → 2

Note that although OBJ is not an array, the PUSH method successfully increases the value of the OBJ object, as if we deal with the actual array.

Characteristics

Compatibility with browser

Feature Web view android Chrome for Android Edge Mobile Firefox for Android Android operating system IOS Safari. SAMSUNG Online Store

The stack allows you to attribute to this history of changes in variable values. Data description and algorithms underlies programming. The stack is the basis for transmitting controls between functions, organizing recursion and references to parameters. Syntax and JavaScript semantics by means of a push () and pop () array methods make it possible to manipulate the meaning and take into account the time factor. The peculiarity of the browser language and its logic can otherwise look at the possibility of time factor.

Data array and logic of its formation

Just describe the variable. It is easy to create an array of variables. An algorithm that uses data is a static and simple solution to the problem. Classic data work:

  • describe (create) variable;
  • assign a value;
  • change the value;
  • delete variable.

Push () and POP () functions allow you to change the essence of variables and use them. The idea of \u200b\u200bstack has not changed since its "birth", but the feature of JS as a browser language and the modern programming concept makes it possible to take into account the time factor and give these dynamics.

The value function ") - add something to the end of the array. The function is to extract the last element of the array. The pointer in the PUSH / POP context is moved to the added element when removing the penultimate element, and the last element is the result of the operation.

Stack of plates - the traditional description of the stack in JavaScript - acquires a new meaning. Let always the variable - this is an array. Actually an array is a combination of variables, but considering the variable as an array, you can otherwise look at the dynamics of changes in its values.

Movement by values

The essence of stack - came the last, went first. You can not remove the value outside of this order. Strictly observing this rule, considering the values \u200b\u200bof the whole array as one variable, you can get the dynamics of changes in the values \u200b\u200bof this variable in time.

In this example, adding JS array.push (...) values \u200b\u200bis one sequence of actions, the extraction of JS Array Pop () values \u200b\u200bis another sequence. Both variants are interrelated. This means that the active element changes its value not only by time, but also by the logic of its change.

Recursion and dynamics

If the function can cause itself and safely fulfill its purpose - this is complete functionality. A simple example is a table. There may be other tables in the table. And each table is lines, columns and cells. Each cell may contain a table. Multiple cells on a row or by a column can be combined into one cell, in which the table may be located. In the table located in the cell, there may be a cell with two and more tables.

It is almost impossible to implement the classic style programming style, but in the recursive - elementary. If the functionality of the work algorithm with the table allows you to realize yourself within any cell means, it is JS Array Push. On javascript, this "focus" has a special meaning. Tables are custom applications. Page tree (DOM) is a job on the page.

On DOM elements (page tags) handlers hang. One option when such a handler is triggered once, a completely different option when it can cause itself many times. In the context of all handlers all the page elements, the time speaker is obtained.

PUSH / POP and recursion is a slightly different idea of \u200b\u200bthe logic of the page of the page: everything changes as required in the current situation, and not programmed in advance in the form of a consistent study of visitor actions.

Massives can be operated by various methods provided by Array designer.

POP / PUSH and SHIFT / UNSHIFT Methods

Consider the POP () and PUSH () methods. These methods allow working with arrays as with stacks. The stack is a data structure in which access to the elements is organized according to the LIFO principle (English. Last In - First Out, "the last one came - the first left"). The principle of operation of the stack can be compared with a stack of plates: to take the second on top, you need to remove the upper one. How it works depicted in the picture:

And so let us return to the consideration of Push () and POP () methods. The Push () method adds one or more new elements to the end of the array and returns it a new length. The POP () method deletes the last element of the array, reduces the length of the array and returns the value remand. It is worth paying attention to the fact that both of these methods change the array in place, and do not create its modified copy.

Var foo \u003d; // Foo: foo.push (1,2); // Foo: Returns 2 foo.pop (); // FOO: Returns 2 Foo.Push (3); // Foo: Returns 2 foo.pop (); // Foo: Returns 3 foo.push (); // FOO:] Returns 2 foo.pop () // Foo: Returns foo.pop (); // Foo: Returns 1 Var Fruits \u003d ["Pears", "Bananas", "Apples"]; var picked \u003d fruits.pop (); Document.Write ("You broke my" + picked); Try

SHIFT () and UNSHIFT () methods behave largely as well as POP () and push (), except that they insert and remove the elements at the beginning of the array. Unshift () method Displays existing elements towards large indices to exemplate space for new elements, adds one or more elements to the beginning of the array and returns a new length of the array. The SHIFT () method deletes the first element of the array and returns its value by shifting all the subsequent elements to occupy free space at the beginning of the array.

Var f \u003d; // F: F.unshift (1); // F: Returns: 1 F.unshift (22); // F: Returns: 2 F.Shift (); // F: Returns: 22 F.unshift (3,); // F:, 1] Returns: 3 F.Shift (); // F: [, 1] Returns: 3 F.Shift (); // F: Returns: F.Shift (); // F: Returns: 1

Join Method

ARRAY.JOIN () method is used to combine an array elements in one line. The method can be transferred to an optional string argument that will be used to separate the elements in the string. If the separator is not specified, then when calling the method, the default symbol will be a comma.

Var a \u003d ["wind", "rain", "fire"]; var myvar1 \u003d a.join (); // "Wind, rain, fire" var myvar2 \u003d a.join (","); // "Wind, rain, fire" var myvar3 \u003d a.join ("+"); // "Wind + rain + fire" Document.Write (MyVar1 + "
"+ MyVar2 +"
"+ MyVar3); try"

ARRAY.JOIN () method is reverse with respect to the String.split () method, which creates an array by splitting the string to fragments.

Reverse method

The array.reverse () method changes the order of the elements in the array to the opposite and return an array with the rearranged elements. This method does not create a new array with reordered elements, and reorders them in an existing array.

Var myarr \u003d ["one", "two", "three"]; document.write (myarr.reverse ()); Try

Concat method

The array.concat () method creates and returns a new array containing the elements of the source array for which the Concat () method was called, consistently complemented by the values \u200b\u200bof all arguments transmitted by the Concat () method. If any of these arguments itself is an array, then all its elements will be added. Array names are used as arguments and are indicated in the order in which their elements need to be combined.

Var a \u003d; a.concat (4, 5) // Returns A.concat (); // The same - returns a.concat (,) // returns

Sort method

The array.sort () method sorts the elements of the array and returns the sorted array. If the Sort () method is called without an argument, it sorts the elements of the array in an alphabetical order (temporarily converts them into strings to compare comparison). As an argument, the Sort () method may receive a comparison function that determines the order of sorting the elements.

Var a \u003d ["kiwi", "oranges", "pears"]; a.sort (); var s \u003d a.join (","); // Oranges, Pear, Kiwi Document.Write (S); // Example with Numbers VAR MYARR \u003d; myarr.sort (); Document.Write (MYARR); // 1,10,2 try "

Probably from sorting numbers you expected to see a little different result. Such a sorting occurred because the SORT () method sorts the elements by transforming them into strings. Therefore, their order is obtained by a string - because "10"

To sort in any other order other than the alphabetic, you can transfer the Sort () method as an argument the comparison function. However, it should be noted that the comparison function will have to be written. This feature must have two parameters, as it sets which of its two arguments should be present earlier in the sorted list. To make it easier to figure out and write such a function, there are several rules for which the order of elements will be determined:

  • If the first argument must precede the second, the comparison function returns a negative number (if a
  • If the first argument should follow the second, then the comparison function returns a positive number (if A\u003e b)
  • If two values \u200b\u200bare equivalent (i.e., the order of their location is not important), the comparison function returns 0 (if A \u003d\u003d b)

For comparison, the function uses the elements of the array as its arguments:

FUNCTION FOO (A, B) (// Determine the function of checking if (A b) Return 1; Return 0; // if a \u003d\u003d b) var a \u003d; a.sort (foo); // only the name of the Document.Write function is transmitted as an argument (A.Join (",")); // also written more shortly var a \u003d; a.sort (FUNCTION (A, B) (// Use the anonymous function Return A - B; // The function returns a value 0)); Document.Write (A); // 1,2,5,10 try "

The first entry is written in the example so that it is easier to understand how it works. Note how convenient to use an anonymous function in the second fragment. It is called only once, so there is no need to give her a name.

Note: If there are uncertain elements in the array (undefined), they are transferred to the end of the array.

Slice method

The array.slice () method is used to copy the specified area from the array and returns a new array containing copied elements. The source array does not change.

Method syntax:

Name_Massiva.slice (Begin, End);

The mail_name should be replaced by the name of that array, from which you need to extract a certain set of elements for a new array. The method takes two arguments that determine the beginning and end of the returned area of \u200b\u200bthe array. The method copies the array portion starting from Begin to END, not including END. If only one argument is specified, the returned array will contain all the elements from the specified position until the end of the array. You can use negative indices - they are counted from the end of the array.

Var arr \u003d; arr.slice (0.3); // Returns Arr.Slice (3); // Returns Arr.Slice (1, -1); // returns arr.slice (-3, -2); // Returns

SPLICE method

The array.splice () method is a universal method for working with arrays. It changes the array in place, and does not return a new modified array, as the Slice () and Concat () methods do. The Splice method can delete elements from the array, insert new elements, replace the elements - in turn and at the same time. It returns an array consisting of remote elements, if none of the items have been removed, will return an empty array.

Method syntax:

Lassiva name.splice (index, count, Elem1, ..., Elemn);

The first argument indicates the index in the array from which the insert or removal of items begins. The second argument sets the number of elements that must be removed from the array starting from the index specified in the first argument if the second argument is 0, then the items will not be deleted. If the second argument is omitted, all the elements of the array starting from the specified index to the end of the array are removed. When using a negative position number, the countdown of the elements will be from the end of the array.

Var fruits \u003d ["oranges", "apples", "pears", "grapes"]; var deleted \u003d fruits.splice (2.2); // Returns ["Pears", "Grapes"] Document.Write (Deleted); var arr \u003d; arr.splice (4); // Returns; The array became: arr.splice (1,2); // Returns; An array became: arr.splice (1,1); // Returns; The array became: try "

The first two arguments of the SPLICE () method set the elements of the array to be removed. For these two arguments, any number of additional arguments specifying elements that will be inserted into an array starting from the position specified by the first argument.

Var fruits \u003d ["oranges", "apples"]; fruits.splice (2.0, "watermelons"); // Returns Document.Write (Fruits); // became ["oranges", "apples", "watermelons"] var arr \u003d; arr.splice (2.0, "a", "b"); // Returns; has become arr.splice (2.2,); // Returns ["A", "B"]; It became, 3,4,5] try "

It is worth paying attention to that, in contrast to Concat (), the SPLICE () method does not break into separate elements of arrays transmitted as arguments. That is, if an array is passed to the method for insertion, it inserts an array itself, and not the elements of this array.

Tostring method

The TOSTRING () method converts the elements of the array in the string using a comma as a split symbol.

Var Arr \u003d ["Milk", "Bread", "Cookies"]; var food \u003d arr.tostring (); Document.Write (Food); // Milk, bread, cookies try "

Note, the method returns the same string as the JOIN () method when calling it without arguments.

indexof and Lastindexof

The indexof method returns the element index whose value is equal to the value transmitted as an argument.

Syntax methods indexof () and Lastindexof ():

Label_name.INDEXOF_name (Skeeping_Element, Index) Name MMassiva.lastindexof (desired_Element, index)

The first argument of the method indicates the value of the element, the index of which you need to find, the second argument (optional), indicates the index from which the search will begin. If the same occurrences are somewhat, the smallest (first) index is selected. If the element with the desired value is not found, the method will return -1. Inside the search method, a strict comparison is used (\u003d\u003d\u003d).

Var a \u003d; A.INDEXOF (3); // returns 2 a.indexof (3.4); // returns 6 A.INDEXOF (35); // return -1: no element with such a value of A.INDEXOF (2); // one

The Lastindexof () method also returns the element index whose value is equal to the value transmitted as an argument. The only difference is that the LastindexOF () method chooses the largest (last) index.

Var a \u003d; a.lastindexof (3); // returns 7 a.lastindexof (35); // return -1: no element with such a value of A.Lastindexof (2); // 6.

Methods of iterators

The methods described below are iterators. In all modern browsers for working with arrays there are methods that are intended for the bustling of elements and perform various actions on them. These are Foreach (), Map (), Filter (), Every (), Some, Reduce () and Reduceright ().

They move the elements of the array starting from 0 to Length - 1 and, if the item exists, transmit it to the Callback processor-function.

foreach.

Method syntax:

Name_Massiva.Foreach (Callback, Thisarg)

As the first argument, the Callback function is indicated that the foreach () method will call for each element of the array. The implementation of the called handler function must be written. The resulting function must have three parameters: the first parameter takes as an argument - the value of the array element, the second is the index of the element, and the third is the array itself. However, if you only need to use the values \u200b\u200bof the array elements, you can write a function with only one parameter. The second argument - thisarg (optional) will be transferred as the value of this.

Var arr \u003d; FUNCTION FOO (VALUE) (VAR SUM \u003d VALUE * THIS; RETURN Document.Write (SUM + "
");) Arr.Foreach (Foo, 5); // The second argument will be transferred as the value of this // Example with three parameters var a \u003d; A.Foreach (FUNCTION (EL, IDX, A) (Document.Write ( "A [" + idx + "] \u003d" + el + "in [" + a + "]
");)); Try"

filter.

Method syntax:

MMassive name.Filter (Callback, ThisObject)

The Filter () method creates and returns a new array that will contain only those elements of the array for which the callback call will return TRUE.

Function Isbig (Element, Index, Array) (// Returns numbers that are greater than or equal to 10 RETURN (Element\u003e \u003d 10); // If the value of the element is greater than or equal to 10 - the expression will return TRUE) var filtered \u003d .filter (ISBIG) ; // Filtered

map

The MAP () method creates and returns a new array that will consist of calling the Callback function (Item, IDX, AR) for each element of the array.

Var a \u003d; VAR B \u003d A.Map (Function (Item, IDX, ARR) (Return Item * Item;)); // B \u003d

every and Some

The EVERY () method returns true if for all the array elements, the specified function used to check them will return True.

The SOME () method returns TRUE if, during the test, one or more items will be returned to the specified function.

Var a \u003d; a.every (X) (RETURN x 10;)) // True: one number\u003e 10

reduce and Reduceright

Method syntax:

Match_Reduce_name (Callback, InitialValue) Name Lassiva.Reduceright (Callback, InitialValue)

The Reduce () method applies the specified function (Callback) in relation to immediately two values \u200b\u200bin the array, turning over the elements from left to right, while maintaining an intermediate result.

Callback function arguments: (PreviousValue, CurrentItem, Index, Array)

  • previousValue - Return result Callback features (it is an intermediate result)
  • currentItem - the current element of the array (items are moved in turn left-topoint)
  • index - the index of the current element
  • array - Array Processed

initialValue (Initializing value) is an object used as the first argument for the first call of the Callback function. Simply put, the value of PreviousValue at the first call is initialValue. If the initialvalue is not, then it is equal to the first element of the array, and the bust starts from the second:

Var a \u003d; FUNCTION FOO (PREVNUM, CURNUM) (SUM \u003d PREVNUM + CURNUM; Alert (SUM); RETURN SUM;) VAR Result \u003d a.Reduce (Foo, 0); Document.Write (Result); Try

We will analyze how this example works. The first arguments of the FOO function are:

  • prevnum \u003d 0 (since initialvalue - 0)
  • cURNUM \u003d 1 (Current element - 1st element of the array)

1. This result (SUM: 1) is added 1. This result will be passed as PrevNUM when the function starts next. And so on until it reaches the last element. Returned Result - the sum of the last launch will be 15 (1 + 2 + 3 + 4 + 5).

The Reduceright method works similarly to the REDUCE method, but it goes on the massif on the right-left:

Var a \u003d ["h", "o", "m", "e"]; FUNCTION BAR (PREVSTR, CURIMEM) (RETURN PREVSTR + CURIEM;) Document.Write (A.Reduceright (BAR)); // Emoh.

In javascript. Here we will continue to get acquainted with arrays. Let's talk about the Length property - how to find out: how many items contain an array?

Teach add elements The beginning and end of the array are UNSHIFT and PUSH methods, respectively.

As well as using SHIFT and POP methods remove elements Also from the beginning and end of the array!

In essence, the array is a certain object consisting of a certain number of different elements.

The Length property will allow to find out the number of elements in the array.

For example, let's take an array of seven days of the week familiar to us by last theme.

Let's learn and bring the number of elements of the array on the screen. To do this, you need as you see in the example below, create a variable, the value of which is the array of interest to us, for which, in turn, is indicated by the Length property.

array.Length - Such code gives us the number of elements of the array (Where array. - the name of the array) .

Thus, in the Count variable we placed a number equal to the number of array elements.

This is how the Length property works.

Push method - adds an element to the end of the array.

In order to start working with the methods of adding items, you need to create any array.

Below I created an array of friends - Friends.

Now we need to add an item, that is, another name in the end of the array.

For this, there is a Push method - it adds an element to the end of the array. It looks like this:

Nastya, Grigory, Vyacheslav, Alexey, Yakov

Yakov

To check the PUSH method in the example above, we brought the number of elements of the Friends array using the Length property - they were 5. Then they brought the entire Friends array as well the last element of the array .

Now you can make sure that the element is added to the end of the array!

Unshift method - adds an item to the top of the massif.

Here we turn back to the array of Friends.

Now we need to add an item to the beginning of the array. To do this, there is a UNSHIFT method.

The number of elements in the array is 5

Boris, Nastya, Grigory, Vyacheslav, Alexey

Boris.

To check the operation of the UNSHIFT method, we derived the number of elements of the Friends array using the Length property, then brought the entire Ariends array as well the first element of the array (We remind you that the numbering of the elements of the array begins with 0) .

Now, as you can see, the element has been added to the beginning of the array!

POP method - removes the last element from the massif.

And again we work with an array of "friends"

Using the POP method - remove the last element from the array:

Nastya, Grigory, Vyacheslav

Vyacheslav

For clarity of the POP method, we again output the number of array elements using the Length property, then the entire Friends array was displayed - without a remote last element.

And also derived the last element The newly received massif . To display the last element by using the Length property, we took the total number of remaining elements in the array (3) and detected from it 1. Thus, we brought the last element of the array at number 2. But this is the third element, since the numbering in the array begins with 0 !!!

SHIFT method - removes the first element of the array.

Before us, as before, the array of "friends"

Using the SHIFT method - remove the first element from the array:

The number of elements in the array is 3

Gregory, Vyacheslav, Alexey

Grigory

And finally, to verify the work of the SHIFT method, we brought the number of elements of the newly received array using the Length property, then brought the entire array of Friends - without a remote first element.

And also derived the first element of the array. The numbering in the array begins with 0 !!!

I remind you for you and for yourself one interesting moment This article!

In order to find out the number / index of the last element of the array, you need from among its items (i.e. from) Subtract one !!!

We have already worked with this at the subject point.

A good option for illustration of this moment will be the continuation of an example from the subject point where we considered an array of seven days of the week.

The number of elements in the DAYS array is 7

The number of the last element of the array is number 6

So, by this example, we once again noted the fact that numbering in the array begins with 0. And, as can be seen from this example, the number of the 7th element of the array is the number 6.

At the end of this topic, I will also perform your homework. And again try to solve it yourself.

Homework to remove from ... and adding elements to an array in JavaScript has the following content:

1. Create an array with fruit: orange, banana, pear.
2. Test on the screen, how much do you have fruit in the array at the moment.
3. Using the methods studied in the previous lesson, add two fruit to the end of the array - Apple and Pineapple, and to the beginning of the massif - grapefruit.
4. Display at the moment you have fruit in the array at the moment.
5. Using the methods studied in the previous lesson, remove the last and first element from the massif.
6. Display at the time you have fruit in the array at the moment.

Orange, Banana, Pear

Now in my basket 3 fruit

Grapefruit, Orange, Banana, Pear, Apple, Pineapple

Now in my basket 6 fruits

Orange, banana, pear, apple

Now in my basket 4 fruit