Answers for "array in javascript"

22

list javascript

//Creating a list
var fruits = ["Apple", "Banana", "Cherry"];

//Creating an empty list
var books = [];

//Getting element of list
//Lists are ordered using indexes
//The first element in an list has an index of 0, 
//the second an index of 1,
//the third an index of 2,
//and so on.
console.log(fruits[0]) //This prints the first element 
//in the list fruits, which in this case is "Apple"

//Adding to lists
fruits.push("Orange") //This will add orange to the end of the list "fruits"
fruits[1]="Blueberry" //The second element will be changed to Blueberry

//Removing from lists
fruits.splice(0, 1) //This will remove the first element,
//in this case Apple, from the list
fruits.splice(0, 2) //Will remove first and second element
//Splice goes from index of first argument to index of second argument (excluding second argument)
Posted by: Guest on June-10-2020
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
0

javascript array

window.location.href
Posted by: Guest on December-12-2020
6

array in javascript

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

array in javascript

var colors = ["red","blue","green"];

//you can loop through an array like this:
for (var i = 0; i < colors.length; i++) {
    document.write(colors[i]);//printing elements of the array 
	}
	colors.push("pink");//adds element to array;
	colors.pop(); // removes last element of the array 
	colors.shift("purple","aqua");//adds one or more items at the front of the array 
	color.reverse();//reverses the array 
	var g=color.indexOf("green");//returns index of value
	var c= color.includes("red");//to search for an element
	color.slice();//splits the array
	color.sort() ; //sorts the array
Posted by: Guest on July-27-2021

Code answers related to "array in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language