Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

Programavimo pagrindai su

Javascript
Vasilij Savin
VU KF ruduo 2020
Objektai ir masyvai
Paskaita 5.
Įvadas

Objektai ir masyvai leidžia logiškai sugrupuoti reikšmių


aibę į vieną kintamąjį.

Metafora:
Objektai ir masyvai yra maišeliai, kur gali būti įvairios
reikšmes ir mes galime manipuliuoti jais kaip grupę, o ne su
kiekvienu element atskirai.
Masyvai
Masyvo koncepcija
Masyvo apibrėžimas

let listNumbers = [2,4,5,10,15];


let index = 3;
console.log(listNumbers[0]);
console.log(listNumbers[index]);

Svarbu prisiminti, kad masyvo numeracija


prasideda nuo 0!!!
Naudingos nuorodos

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array

Array pratimai:
https://www.w3resource.com/javascript-exercises/javascript-array-exercises.php
https://medium.com/@andrey.igorevich.borisov/10-javascript-exercises-with-arrays-c44eea1
29fba
Objektai
Objekto savybės (properties)

let str = "Mano labai svarbi eilute";


console.log(str.length);

console.log(Math.max);
Specialūs atvejai

 Almost all JavaScript values have properties. The exceptions are null and undefined. If


you try to access a property on one of these nonvalues, you get an error.
 null.length; // → TypeError: null has no properties
Prieiga prie savybės

The two main ways to access properties in JavaScript are with a dot and with square brackets.
Both value.x and value[x] access a property on value—but not necessarily the same property.
The difference is in how x is interpreted. When using a dot, the word after the dot is the
literal name of the property. When using square brackets, the expression between the brackets
is evaluated to get the property name. Whereas value.x fetches the property of value named
“x”, value[x] tries to evaluate the expression x and uses the result, converted to a string, as
the property name.
 if you want to access a property named 2 or John Doe, you must use square
brackets: value[2] or value["John Doe"].

You might also like