javaScript (не JAVA) является наиболее часто используемым языком кода для веб-разработки в мире. В основном используется во фронтенд-разработке.
В jS есть тип данных с именем массив. По сути, это список любых типов данных, его можно даже смешивать в одном массиве.
JavaScript (без JAVA) используется на языке кодирования для использования в Интернете в мире. Principalmente es usado para el desarrollo de ‘front-end’. Mientras que 'back-end' usa otros lenguajes.
В javaScript есть тип слова "массив". Es basicamente una lista de cualquier tipo de datos, que incluso pueden estar mezclados.
Основные функции для работы с массивами:
Основные функции для работы с массивами:
// Here I create a list of elements. In this case are objects, specifically pets. // Each pet has name and age const listPets = [ { name: 'fifi', age: 5 }, { name: 'toby', age: 2 }, { name: 'zeus', age: 1 }, ] // we iterate throw the list and print the pets names for(let eachPet of listPets){ console.log(eachPet.name) // por ejemplo } // map, filter, find, findIndex - all works with arrow functions // map // crates a new array, based in the original one // in this case I add a new attribute 'race' to the pets const petsWithRace = listPets.map((pet) => { pet.race = ''; return pet }); console.log(petsWithRace); // filter // creates a new array with, in this case, all pets with ages under 3 const petsYoung = listPets.filter((pet) => pet.age < 3); console.log(petsYoung); // find // returns only the first element of the array with the given characteristic const findPet = listPets.find(pet => pet.name === 'zeus'); console.log(findPet); // findIndex // returns the index of the element that has, in this case, the name 'toby' const indexPet = listPets.findIndex(pet => pet.name === 'toby'); console.log(indexPet) // insert a new element at the end of the array listPets.push({ name: 'anacleta', age: 1 }); console.log(listPets); // remove element listPets.splice(indexPet, 1) // (first item to delete, how many from this one) console.log(listPets)