Answers for "Javascript Array()"

140

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
1

array

my_list = [-15, -26, 15, 1, 23, -64, 23, 76]
new_list = []

while my_list:
    min = my_list[0]  
    for x in my_list: 
        if x < min:
            min = x
    new_list.append(min)
    my_list.remove(min)    

print(new_list)
Posted by: Guest on July-24-2021
9

js array

var colors = [ "red", "orange", "yellow", "green", "blue" ]; //Array

console.log(colors); //Should give the whole array
console.log(colors[0]); //should say "red"
console.log(colors[1]); //should say "orange"
console.log(colors[4]); //should say "blue"

colors[4] = "dark blue" //changes "blue" value to "dark blue"
console.log(colors[4]); //should say "dark blue"
//I hope this helped :)
Posted by: Guest on June-21-2020
5

array javascript

//Their are no lists in javascript, they are called arays,wich are basically the same thing

var fruits = ['Apple', 'Banana'];

console.log(fruits.length);
// 2
var first = fruits[0];
// Apple

var last = fruits[fruits.length - 1];
// Banana

fruits.forEach(function(item, index, array) {
  console.log(item, index);
});
// Apple 0
// Banana 1

var newLength = fruits.push('Orange');
// ["Apple", "Banana", "Orange"]

var last = fruits.pop(); // deletes orange
// ["Apple", "Banana"];

var first = fruits.shift(); // supprime Apple (au début)
// ["Banana"];

var newLength = fruits.unshift('Strawberry') // adds to the start
// ["Strawberry", "Banana"];

fruits.push('Mango');
// ["Strawberry", "Banana", "Mango"]

var pos = fruits.indexOf('Banana');
// 1

var removedItem = fruits.splice(pos, 1); // deletes on element at the position pos
//removes one element at the position pos
// ["Strawberry", "Mango"]




var vegetables = ['Cabbage', 'Turnip', 'Radish', 'Carrot'];
console.log(vegetables);
// ["Cabbage", "Turnip", "Radish", "Carrot"]

var pos = 1, n = 2;

var removedItems = vegetables.splice(pos, n);
// n defines the number of element to delete starting from pos

console.log(vegetables);
// ["Cabbage", "Carrot"] 
console.log(removedItems);
// ["Turnip", "Radish"] (splice returns list of deleted objects)
Posted by: Guest on February-18-2021
1

array javascript

special_dates = [];
special_dates.push(new Date('2021/02/12').getTime());
special_dates.push(new Date('2021/02/13').getTime());
special_dates.push(new Date('2021/02/14').getTime());

			
for (var i = 0; i < special_dates.length; i++) {
 console.log(special_dates[i]) ;
}
Posted by: Guest on February-04-2021
0

javascript array

//array methods
https://stackoverflow.com/questions/351409/how-to-append-something-to-an-array
Posted by: Guest on August-06-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language