how to add elements of array in javascript code example
Example 1: javascript append to array
var colors=["red","white"];
colors.push("blue");
Example 2: 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]));
}
Example 3: add item to array javascript
const arr1 = [1,2,3]
const newValue = 4
const newData = [...arr1, obj]
Example 4: how to append an element to an array in javascript
array_name.push(element);
let fruits = ["Mango", "Apple"];
fruits.push("Orange");