Docsity
Docsity

Prepara tus exámenes
Prepara tus exámenes

Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity


Consigue puntos base para descargar
Consigue puntos base para descargar

Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium


Orientación Universidad
Orientación Universidad


Fundamentos de programación: estructuras de datos en JavaScript, Diapositivas de Programación Javascript

Los conceptos básicos de las estructuras de datos en JavaScript, incluyendo arrays y objetos. Se explican las propiedades y métodos de arrays, así como la mutabilidad y la creación de objetos. También se muestran ejemplos de código para ilustrar los conceptos explicados.

Tipo: Diapositivas

2020/2021

Subido el 30/07/2021

cta-bbx
cta-bbx 🇪🇸

1 documento

1 / 42

Toggle sidebar

Esta página no es visible en la vista previa

¡No te pierdas las partes importantes!

bg1
Programming fundamentals
4. Data Structures: Arrays and Objects Introduction
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a

Vista previa parcial del texto

¡Descarga Fundamentos de programación: estructuras de datos en JavaScript y más Diapositivas en PDF de Programación Javascript solo en Docsity!

Programming fundamentals

4. Data Structures: Arrays and Objects Introduction

What we will see in this presentation

Data Sets

JavaScript provides a data type specifically for storing sequences of values. It

is called an array and is written as a list of values between square brackets,

separated by commas.

Array

var colors = ["Blue", "Orange", "Green", "Red", "Black"];

var colors = new Array("Blue", "Orange", "Green", "Red", "Black");

Array properties

Javascript

The JavaScript Array object is a global object that is used in the construction of arrays.
An array is a special type of variable that allows you to store multiple values in a single
variable.

Array properties

var colors = new Array("Blue", "Orange");

var colorsLength = colors.length; // => 2

Count Array Elements

PHP

Unlike Javascript, in PHP arrays do not have properties like length, so it is necessary

to use the native functions to be able to count the elements in the array.

$colors = ["Blue", "Orange", "Green", "Red", "Black"];

$colorsLength = count($colors); $colorsLength = sizeof($colors);

Count Array Elements

When working with arrays , there are several default methods

which we can use to modify or read the contents of arrays.

These methods are quite common among programming languages.
One of the default methods that we can use is push() , which allows us to add value to
the end of an array.

Array.push

let sequence = [1, 2, 3]; sequence.push(4); sequence.push(5); console.log(sequence); // → [1, 2, 3, 4, 5]

const cities = [ "Barcelona", "Madrid", "Lisbon" ];

cities.forEach(function (city) { console.log(city); });

// Barcelona // Madrid // Lisbon

Array.forEach

The forEach() method is used to
execute a callback function for each of
the elements in the array rather than
using a for or while loop.

Array.map

The map() method is used to execute a
callback function for each of the
elements in the array and returns a
new array with the elements changed.

const cities = [ "Barcelona", "Madrid" ];

let newCities = cities.map(function (city) { return City name is ${city}; });

// [ // "City name is Barcelona", // "City name is Madrid" // ]

const elements = ["Fire", "Air", "Water"];

console.log(elements.join()); // "Fire,Air,Water"

console.log(elements.join("")); // "FireAirWater"

console.log(elements.join("-")); // "Fire-Air-Water"

Array.join

The join() method creates and returns
a new string by concatenating all of the
elements in an array separated by
commas or a specified separator string.

let firstHalf = ["Monday", "Tuesday", "Wednesday"]; let secondHalf = ["Thursday", "Friday"];

let weekDays = firstHalf.concat(secondHalf);

console.log(weekDays); // [ // "Monday", // "Tuesday", // "Wednesday", // "Thursday", // "Friday" // ];

Array.concat

The concat() method is used to merge
two or more arrays. This method does
not change the existing arrays, but
instead returns a new array.