javascript pushing to an array
some_array = ["John", "Sally"];
some_array.push("Mike");
console.log(some_array); //output will be =>
["John", "Sally", "Mike"]
javascript pushing to an array
some_array = ["John", "Sally"];
some_array.push("Mike");
console.log(some_array); //output will be =>
["John", "Sally", "Mike"]
javascript array
//create an array like so:
var colors = ["red","blue","green"];
//you can loop through an array like this:
for (var i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
how to make an array in javascript
var names = ["Sanjith", "Pranav", "Aadya", "Saharsh"]
js arrays
// Making an array:
const colors = ["red", "orange", "yellow"];
// Arrays are indexed like strings:
colors[0]; // "red"
// They have a length:
colors.length; //3
// Important array methods:
//push(value) - adds value to the END of an array
//pop() - removes and returns last value in array
//unshift(val) - adds value to START of an array
//shift() - removes and returns first element in an array
js arrays
// A javascript array is a list of elements in one variable.
//make an array like this:
var array = ["Nothing", "Something", 510, "anything"]
//You can log how many elements are in the array:
console.log(array.length);
// You can log a ["With your text and numbers in here"]:
console.log(array)
//you can also loop through an array like this:
for (var i = 0; i < array.length; i++) {
console.log(array[i]);
}
// "pop" will remove the last element from the array
var poppedarray = array.pop()
// Will output: ["Nothing", "Something", 510].
var pushedarray = array.push("anything");
// Now back to the original!
// now get the position of an element and their name:
fruits.forEach(function(item, index, array) {
console.log(item, index);
});
// Nothing 0
// Something 1
// 510 2
// Anything 3
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us