var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("strawberry")
No edit summary |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
The Push() method adds an ''item'' to end of an ''array''. This function changes the original array. It returns the number of items in the array after adding the new item. | The Push() method adds an ''item'' to end of an ''array''. This function changes the original array. It returns the number of items in the array after adding the new item. | ||
== Example | == Example == | ||
<tabber> | |||
< | JavaScript= | ||
<syntaxhighlight lang="JavaScript"> | |||
var fruits = ["Banana", "Orange", "Apple", "Mango"]; | |||
fruits.push("strawberry") | |||
</syntaxhighlight> | |||
|-| | |||
BASIC= | |||
<syntaxhighlight lang="vb.net"> | |||
fruits = ["Banana", "Orange", "Apple", "Mango"] | fruits = ["Banana", "Orange", "Apple", "Mango"] | ||
count=Push(fruits,"Strawberry") | count=Push(fruits,"Strawberry") | ||
</ | </syntaxhighlight> | ||
</tabber> | |||
< | |||
== Output == | |||
The new value of fruits will be: | The new value of fruits will be: | ||
<pre> | <pre> | ||
Line 35: | Line 35: | ||
[[Category:Variable Handling]] | [[Category:Variable Handling]] | ||
[[Category:BASIC Functions]] |
Push(array, item)
The Push() method adds an item to end of an array. This function changes the original array. It returns the number of items in the array after adding the new item.
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("strawberry")
fruits = ["Banana", "Orange", "Apple", "Mango"]
count=Push(fruits,"Strawberry")
The new value of fruits will be:
Banana,Orange,Apple,Mango,Strawberry