how to push items in array in javascript


array.push(element)

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");

let items = [1, 2, 3]
items.push(4); // items = [1, 2, 3, 4]

//the array comes here
var numbers = [1, 2, 3, 4];

//here you add another number
numbers.push(5);

//or if you want to do it with words
var words = ["one", "two", "three", "four"];

//then you add a word
words.push("five")

//thanks for reading

array = ["hello"]
array.push("world");

www.codegrepper.com
www.stackoverflow.com

how to push multiple data to different parents in a single request in firebase


var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
// Generate a new push ID for the new post
var newPostRef = ref.child("posts").push();
var newPostKey = newPostRef.key();
// Create the data we want to update
var updatedUserData = {};
updatedUserData["user/posts/" + newPostKey] = true;
updatedUserData["posts/" + newPostKey] = {
title: "New Post",
content: "Here is my new post!"
};
// Do a deep-path update
ref.update(updatedUserData, function(error) {
if (error) {
console.log("Error updating data:", error);
}
});

www.codegrepper.com
www.stackoverflow.com

how to push values in array


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

console.log(some_array); //output will be =>
["John", "Sally", "Mike"]

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

var fruits = ["Banana", "Orange", "Apple", "Mango"];

fruits.push("Kiwi");

array.push(element)

const animals = ['pigs', 'goats', 'sheep'];

const count = animals.push('cows');
console.log(count);
// expected output: 4
console.log(animals);
// expected output: Array ["pigs", "goats", "sheep", "cows"]

animals.push('chickens', 'cats', 'dogs');
console.log(animals);
// expected output: Array ["pigs", "goats", "sheep", "cows", "chickens", "cats", "dogs"]

www.codegrepper.com
www.stackoverflow.com

how to push an element into an array in javascript


var colors=["red","white"];
colors.push("blue");//append 'blue' to colors

array.push(element)

var colors= ["red","blue"];
colors.push("yellow");

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

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

console.log(arr);

var fruits = ["Banana", "Orange", "Apple", "Mango"];

fruits.push("Kiwi");

www.codegrepper.com
www.stackoverflow.com

how to push array


var fruits = ["Banana", "Orange", "Apple", "Mango"];

fruits.push("Kiwi");

array = ["hello"]
array.push("world");

console.log(array);
//output =>
["hello", "world"]

const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");

var array = [];
var element = "anything you want in the array";
array.push(element); // array = [ "anything you want in the array" ]

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");

//the array comes here
var numbers = [1, 2, 3, 4];

//here you add another number
numbers.push(5);

//or if you want to do it with words
var words = ["one", "two", "three", "four"];

//then you add a word
words.push("five")

//thanks for reading

www.codegrepper.com
www.stackoverflow.com