Javascript array methods!

dawroun

Davron

Posted on May 25, 2022

Javascript array methods!

Boshladik!

1.concat()

Bu massiv boshqa massiv(lar) va/yoki qiymat(lar) bilan birlashtirilgan yangi massivni qaytaradi.

const mevalar = ['πŸ‰', '🍎', 'πŸ’', '🍌'];
const sabzavotlar = ['πŸ§…', '🌽', 'πŸ₯•', 'πŸ₯‘'];

// 1. concat()
const food = mevalar.concat(sabzavotlar); // ["πŸ‰", "🍎", "πŸ’", "🍌", "πŸ§…", "🌽", "πŸ₯•", "πŸ₯‘"]
Enter fullscreen mode Exit fullscreen mode

2.copyWithin()

Massiv ichidagi massiv elementlari ketma-ketligini ko'chiradi/nusxalaydi.

// 2. copyWithin()
const mevalar = ['πŸ‰', '🍎', 'πŸ’', '🍌'];

const fruitsCopy = mevalar.copyWithin(0, 2); // ["πŸ’", "🍌", "πŸ’", "🍌"]
Enter fullscreen mode Exit fullscreen mode

3.every()

Agar ushbu massivdagi har bir element funksiyasi shartiga javob bersa, true qiymatini qaytaradi.

// 3. every()
const mevalar = ['πŸ‰', '🍎', 'πŸ’', '🍌'];

const allBananas = mevalar.every(meva => meva === '🍌'); // false
Enter fullscreen mode Exit fullscreen mode

4. fill()

Massivning barcha elementlarini boshlang'ich indeksdan yakuniy indeksgacha statik qiymat bilan to'ldiradi.

// 4. fill()
const mevalar = ['πŸ‰', '🍎', 'πŸ’', '🍌'];

const lemons =  mevalar.fill('πŸ‹'); // ["πŸ‹", "πŸ‹", "πŸ‹", "πŸ‹"]
Enter fullscreen mode Exit fullscreen mode

5. filter()

Taqdim etilgan filtrlash funksiyasi true qiymatini qaytaradigan chaqiruvchi massivning barcha elementlarini o'z ichiga olgan yangi massivni qaytaradi.

// 5. filter()
const mevalar = ['πŸ‰', '🍎', 'πŸ’', '🍌'];

const onlyBananas = ['πŸ‰', '🍎', '🍌', '🍌'].filter(meva => meva === '🍌'); // ["🍌", "🍌"]
Enter fullscreen mode Exit fullscreen mode

6. find()

Agar massivdagi ba'zi element funksiyasi shartiga javob bersa massivdagi topilgan elementni qaytaradi yoki topilmasa, undefined qaytaradi.

// 6. find()
const mevalar = ['πŸ‰', '🍎', 'πŸ’', '🍌'];

const cherry = mevalar.find(meva => meva === 'πŸ’'); // "πŸ’"
Enter fullscreen mode Exit fullscreen mode

7. findIndex()

Agar massivdagi element funksiya shartiga javob bersa, topilgan indeksni, javob bermasa, -1 ni qaytaradi.

// 7. findIndex()
const mevalar = ['πŸ‰', '🍎', 'πŸ’', '🍌'];

const cherryIndex = mevalar.findIndex(meva => meva === 'πŸ’'); // 2
Enter fullscreen mode Exit fullscreen mode

8. forEach()

Massivdagi har bir element uchun funksiyani chaqiradi.

// 8. forEach()
const sabzavotlar = ['πŸ§…', '🌽', 'πŸ₯•', 'πŸ₯‘'];

sabzavotlar.forEach(sabzavot => console.log(sabzavot));
// "πŸ₯¦"
// "🌽"
//  "πŸ₯•"
//  "πŸ₯‘"
Enter fullscreen mode Exit fullscreen mode

9. includes()

Berilgan qiymat massivda bor yo'qligini aniqmaydi va mos ravishda true yoki false qiymat qaytaradi.

// 9. includes()
const sabzavotlar = ['πŸ§…', '🌽', 'πŸ₯•', 'πŸ₯‘'];

const includesCorn = sabzavotlar.includes('🌽'); // true
const includesTomato = sabzavotlar.includes('πŸ…'); // false
Enter fullscreen mode Exit fullscreen mode

10. join()

Massivning barcha elementlarini string'ga birlashtiradi.

// 10. join()
const sabzavotlar = ['πŸ§…', '🌽', 'πŸ₯•', 'πŸ₯‘'];

const vegetablesGroup = sabzavotlar.join(''); // "πŸ₯¦πŸŒ½πŸ₯•πŸ₯‘"
Enter fullscreen mode Exit fullscreen mode

11. map()

Ushbu massivdagi har bir element uchun chaqirilgan funksiyaning natijalarini o'z ichiga olgan yangi massivni qaytaradi.

// 11. map()
const sabzavotlar = ['πŸ§…', '🌽', 'πŸ₯•', 'πŸ₯‘'];

const doubledVegetables = sabzavotlar.map(sabzavot => sabzavot + sabzavot); 
// ["πŸ₯¦πŸ₯¦", "🌽🌽", "πŸ₯•πŸ₯•", "πŸ₯‘πŸ₯‘"]
Enter fullscreen mode Exit fullscreen mode

12. push()

Massiv oxiriga bir yoki bir nechta element qoβ€˜shadi va massivning yangi uzunligini qaytaradi.

// 12. push()
const mevalar = ['πŸ‰', '🍎', 'πŸ’', '🍌'];

mevalar.push('πŸ₯'); // ["πŸ‰", "🍎", "πŸ’", "🍌", "πŸ₯"]
Enter fullscreen mode Exit fullscreen mode

13. reverse()

Massiv elementlarining joydagi tartibini oβ€˜zgartiradi.

// 13. reverse()
const mevalar = ['πŸ‰', '🍎', 'πŸ’', '🍌'];

const mevalar = ['πŸ‰', '🍎', 'πŸ’', '🍌'];

const reversedFruits = mevalar.reverse(); // ["🍌", "πŸ’", "🍎", "πŸ‰"]
Enter fullscreen mode Exit fullscreen mode

14. slice()

Chaqiriluvchi massivning bir qismini chiqaradi va yangi massivni qaytaradi.

// 14. slice()
const mevalar = ['πŸ‰', '🍎', 'πŸ’', '🍌'];

mevalar.slice(2); // ["πŸ’", "🍌"]
Enter fullscreen mode Exit fullscreen mode

15. some()

Agar ushbu massivdagi kamida bitta element funksiya shartiga javob bersa, true qiymatini qaytaradi.

// 15. some()
const mevalar = ['πŸ‰', '🍎', 'πŸ’', '🍌'];

const bananaExists = mevalar.some(meva => meva === '🍌')); // true
Enter fullscreen mode Exit fullscreen mode
  1. sort() Massiv elementlarini joyida saralaydi va massivni qaytaradi.
// 16. sort()
const mevalar = ['πŸ‰', '🍎', 'πŸ’', '🍌', 'πŸ‰', 'πŸ‰', 'πŸ’', '🍎', '🍌'];
mevalar.sort(); // ["πŸ‰", "πŸ‰", "πŸ‰", "🍌", "🍌", "🍎", "🍎", "πŸ’", "πŸ’"]
Enter fullscreen mode Exit fullscreen mode

17. splice()

Massivga elementlarni qoβ€˜shadi va/yoki oβ€˜chiradi.

// 17. splice()
const mevalar = ['πŸ‰', '🍎', 'πŸ’', '🍌'];

mevalar.splice(2, 1, 'πŸ₯'); // ["πŸ‰", "🍎", "πŸ₯", "🍌"]
Enter fullscreen mode Exit fullscreen mode

Agar maqola sizga manzur bo'lgan bo'lsa, ❀️ bosishni unutmang!

Agar qandaydir savolingiz bo'lsa ushbu Telegram ❀️ orqali bog'laning!

πŸ’– πŸ’ͺ πŸ™… 🚩
dawroun
Davron

Posted on May 25, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related