Answers for "js arrays"

48

javascript pushing to an array

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

console.log(some_array); //output will be =>
["John", "Sally", "Mike"]
Posted by: Guest on November-12-2019
138

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]);
}
Posted by: Guest on July-01-2019
12

how to make an array in javascript

var names = ["Sanjith", "Pranav", "Aadya", "Saharsh"]
Posted by: Guest on August-31-2020
6

array in javascript

var a=[];
Posted by: Guest on October-26-2020
4

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
Posted by: Guest on January-05-2021
0

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
Posted by: Guest on July-29-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language