js push return array code example
Example 1: js push array
var array = [];
var element = "anything you want in the array";
array.push(element); // array = [ "anything you want in the array" ]
Example 2: javascript array push
let animals = ["dog","cat","tiger"];
animals.pop(); // ["dog","cat"]
animals.push("elephant"); // ["dog","cat","elephant"]
Example 3: how to append object in array javascript
var select =[2,5,8];
var filerdata=[];
for (var i = 0; i < select.length; i++) {
filerdata.push(this.state.data.find((record) => record.id == select[i]));
}
//I have a data which is object,
//find method return me the filter data which are objects
//now with the push method I can make array of objects
Example 4: javascript array push
var fruits = [ "Orange", "Apple", "Mango"];
fruits.push("Banana");
Example 5: array.push
var vegetables = ['Capsicum',' Carrot','Cucumber','Onion'];
vegetables.push('Okra');
//expected output ['Capsicum',' Carrot','Cucumber','Onion','Okra'];
// .push adds a thing at the last of an array