How to Push multiple Values to an Array in JavaScript-Code Examples

Radu TM

How to Push multiple Values to an Array in JavaScript

JavaScript by Radu TM June 21, 2022

// How to Push Multiple Values to an Array in JavaScript

// Create an array and assign values
const myArray = ['🌎', '🌍', '🌏'];

// Use the push() method to add values to the end of the array
myArray.push('🌐');

// The push() method returns the new length of the array
console.log(myArray.push('🌑')); // 5

// The new length of the array is 5
console.log(myArray); // [ '🌎', '🌍', '🌏', '🌐', '🌑' ]

0

21.700

How to Push multiple Values to an Array in JavaScript

JavaScript by Radu TM June 21, 2022

const array = [];

// push one value
array.push('🐶');

// push multiple values
array.push('🐱', '🐭', '🐹');

console.log(array);
// expected output: Array ['🐶', '🐱', '🐭', '🐹']

0

21.700

How to Push multiple Values to an Array in JavaScript

JavaScript by Radu TM June 21, 2022

const myArray = [];

myArray.push('🍎', '🍊', '🍋');

console.log(myArray);
// Output: ['🍎', '🍊', '🍋']

0

21.700

Related JavaScript Queries

Latest JavaScript Queries

Explore code examples by categories