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
j oin () 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();
Do'stlaringiz bilan baham: |