js push apply code example
Example 1: javascript push array
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"]
Example 2: javascript add element to array
const langages = ['Javascript', 'Ruby', 'Python'];
langages.push('Go'); // => ['Javascript', 'Ruby', 'Python', 'Go']
const dart = 'Dart';
langages = [...langages, dart]; // => ['Javascript', 'Ruby', 'Python', 'Go', 'Dart']