Q:

js add item to array

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

fruits.push("Banana"); 
4
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");
7
let langages = ['Javascript', 'Ruby', 'Python']
langages.push('Go') // => ['Javascript', 'Ruby', 'Python', 'Go']

const dart = 'Dart'
langages = [...langages, dart] // => ['Javascript', 'Ruby', 'Python', 'Go', 'Dart']
0
const arr1 = [1,2,3]
const newValue = 4
const newData = [...arr1, obj] // [1,2,3,4]
4
//adding items to array
objects = [];
objects.push("you can add a string,number,boolean,etc");
//if you more stuff in a array
//before i made a error doing value = : value
objects.push({variable1 : value, variable2 : value);
//we do the {} so we tell it it will have more stuff and the variable : value
0

New to Communities?

Join the community