It is a JavaScript Array push method. push() function is used to push one or more values into the array. This function changes the length of the array by the number of elements added to the array. The syntax of the function is as follows:
arr.push(element1[, ...[, elementN]])
The push() method adds one or more elements to the end of an array and returns the new length of the array.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
I have through your question. Push is the method of javascript used to add the element in the array. Push is the same as the add method in the java. Some points about push methods are:- 1:- The push() method adds new items to the end of an array and returns the new length. 2:- The new item(s) will be added at the end of the array. 3:- You can also more the one item at a time.
Example:--
var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.push("Kiwi"); var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.push("Kiwi", "Lemon", "Pineapple");
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards, Deepali Kulshrestha www.kdeepali.com
Greetings to you!
It is a JavaScript Array push method. push() function is used to push one or more values into the array. This function changes the length of the array by the number of elements added to the array. The syntax of the function is as follows:
The push() method adds one or more elements to the end of an array and returns the new length of the array.
https://www.w3schools.com/jsref/jsref_push.asp
https://appdividend.com/2018/10/08/javascript-array-push-example-array-prototype-tutorial/
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
* Please refer through below link, it crearly explain the use of .Push operation in Lightning Controller:
https://salesforce.stackexchange.com/questions/184465/how-to-add-an-item-to-an-array-to-show-in-lightning-component
https://stackoverflow.com/questions/51443599/how-to-add-more-data-an-array-of-objects-in-a-lightning-component
eg.,
controller.js---->
({
doInit: function(component, event, helper) {
helper.populateObjectList(component, event);
},
handleClick: function(component, event, helper) {
helper.augmentObject(component, event);
}
})
helper.js---->
({
populateObjectList: function(component, event) {
var objs = [];
objs.push(this.createObj('iPhone', 34000));
objs.push(this.createObj('Motox', 27000));
objs.push(this.createObj('Oneplus', 33033));
component.set('v.objs', objs);
},
createObj: function(product, price) {
var obj = new Object();
obj.product = product;
obj.price = price;
return obj;
},
augmentObject: function(component, event) {
var objs = component.get('v.objs');
objs.push(this.createObj('Demo', 1000));
component.set('v.objs', objs);
}
})
Component---->
<!-- lightning component -->
<!-- component A -->
<aura:component>
<aura:attribute name="objs" type="Object[]" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<table>
<tr>
<th>Product</th>
<th>Price</th>
</tr>
<aura:iteration items="{!v.objs}" var="obj">
<tr>
<td>{!obj.product}</td>
<td>{!obj.price}</td>
</tr>
</aura:iteration>
</table>
<!-- component B -->
<lightning:button variant="brand" label="Add another" title="Brand action" onclick="{! c.handleClick }" />
</aura:component>
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
I have through your question. Push is the method of javascript used to add the element in the array. Push is the same as the add method in the java.
Some points about push methods are:-
1:- The push() method adds new items to the end of an array and returns the new length.
2:- The new item(s) will be added at the end of the array.
3:- You can also more the one item at a time.
Example:--
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi", "Lemon", "Pineapple");
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com