Answers for "how to add an item to an array"

PHP
48

javascript pushing to an array

some_array = ["John", "Sally"];
some_array.push("Mike");

console.log(some_array); //output will be =>
["John", "Sally", "Mike"]
Posted by: Guest on November-12-2019
32

js array add element

array.push(element)
Posted by: Guest on September-23-2019
2

php add element to array

<?php
$stack = array("orange", "banana");
array_push($stack, "apple", "raspberry");
?>
Posted by: Guest on October-12-2020
2

append an array

// initialize array
var arr = [
  "Hi",
  "Hello",
  "Bonjour"
];

// append new value to the array
arr.push("Hola");

console.log(arr);
Posted by: Guest on February-15-2020
1

javascript append to array

arr = [1, 2, 3, 4]
arr.push(5) // adds element to end

arr.unshift(0) // adds element to beginning
Posted by: Guest on November-24-2020
0

adding an item to an array

addItems = items => {
  this.setState({
    emp: [
      ...this.state.emp,
      ...items
    ]
  })
}
Posted by: Guest on June-02-2021

Code answers related to "how to add an item to an array"

Browse Popular Code Answers by Language