push all elements in array javascript code example
Example 1: javascript pushing to an array
some_array = ["John", "Sally"];
some_array.push("Mike");
console.log(some_array);
["John", "Sally", "Mike"]
Example 2: add all elements in array javascript
console.log(
[1, 2, 3, 4].reduce((a, b) => a + b, 0)
)
console.log(
[].reduce((a, b) => a + b, 0)
)
Example 3: javascript array push
var SomeRandomArray = [];
SomeRandomArray.push("Hello, world!");
Example 4: push another array to array typescript
var arrayA = [1, 2];
var arrayB = [3, 4];
var newArray = arrayA.concat(arrayB);
Example 5: push object into array javascript
var nietos = [];
var obj = {};
obj["01"] = nieto.label;
obj["02"] = nieto.value;
nietos.push(obj);
Example 6: adding all elements in an array javascript
values.reduce(function(a, b){return a+b;})