Informatică, întrebare adresată de Utilizator anonim, 8 ani în urmă

Ma poate ajuta cineva? trebuie lucrate in JavaScript
1. For the following array: var myArray = [ "Ryu", "Ken", "Chun-Li", "Cammy", "Guile", "Sakura", "Sagat", "Juri" ]; do the following
Go over each item in the array and print its position number after the name inside parentheses, for example "Ryu (0)"
Change the last item in the array to “Boris”.
Add two new names to the end of the array.
2. For the following array: const birds = [ "Parrots", "Falcons", "Eagles", "Emus", "Caracaras", "Egrets" ]; do the following:

Find the position of the "Eagles" element
Use the position to change the element from "Eagles" to "Pidgeons"

Răspunsuri la întrebare

Răspuns de andrei750238
1

► PROBLEMA 1 :

var myArray = [ "Ryu", "Ken", "Chun-Li", "Cammy", "Guile", "Sakura", "Sagat", "Juri" ];

for(var i=0;i<myArray.length; i++){

 console.log(myArray[i] + " ("+i+")");

}

myArray[myArray.length-1]="Boris";

myArray.push("Andrei");

myArray.push("Alexandru");

► PROBLEMA 2:

const birds = [ "Parrots", "Falcons", "Eagles", "Emus", "Caracaras", "Egrets" ];

var EaglesPos = birds.findIndex(element => element==="Eagles")

birds[EaglesPos] = "Pidgeons";

Alte întrebări interesante