Java Script uchun qo’llanma Samarqand Davlat universiteti talabasi Ibrohimov Ismoiljon tomonidan tayyorlandi. Kamchiliklar uchun uzr…!


Massivlarni satrlarga aylantirish


Download 227.69 Kb.
bet19/22
Sana04.04.2023
Hajmi227.69 Kb.
#1325028
1   ...   14   15   16   17   18   19   20   21   22
Bog'liq
JS ( Ibrohimov )

Massivlarni satrlarga aylantirish


JavaScript usuli toString()massivni (vergul bilan ajratilgan) massiv qiymatlari qatoriga aylantiradi.

Misol


const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo").innerHTML = fruits.toString();
Natija:
Banana,Orange,Apple,Mango
join() barcha massiv elementlarini satrga birlashtiradi.
U xuddi toString() kabi ishlaydi, lekin qo'shimcha ravishda siz ajratuvchini belgilashingiz mumkin:

Misol


const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo").innerHTML = fruits.join(" * ");
Natija:
Banana * Orange * Apple * Mango


JavaScript massivi pop()


Pop() massivdan oxirgi elementni olib tashlaydi:

Misol


const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.pop();
pop() "chiqarilgan" qiymatni qaytaradi:

Misol


const fruits = ["Banana", "Orange", "Apple", "Mango"];
let fruit = fruits.pop();


JavaScript Array push()


push()massivga yangi element qo'shadi (oxiridan):

Misol


const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");
push()yangi massiv uzunligini qaytaradi:

Misol


const fruits = ["Banana", "Orange", "Apple", "Mango"];
let length = fruits.push("Kiwi");


JavaScript massivini siljitish()


shift()massivning birinchi elementini olib tashlaydi va qolgan barcha elementlarni pastki indeksga "o'tkazadi".

Misol


const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.shift();
shift()"o'chirilgan" qiymatni qaytaradi:

Misol


const fruits = ["Banana", "Orange", "Apple", "Mango"];
let fruit = fruits.shift();

Download 227.69 Kb.

Do'stlaringiz bilan baham:
1   ...   14   15   16   17   18   19   20   21   22




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling