Complex Data Types - Objects and Arrays.

 Noocyada Xogta Adag ee JavaScript - Objects iyo Arrays

JavaScript waxay bixisaa noocyo xogta adag oo muhiim ah si loo maareeyo loona shaqeeyo xogta ka kooban dhowr qayb. Laba ka mid ah noocyada xogta adag ee ugu muhiimsan waa Objects iyo Arrays. Labadani waxay kuu oggolaanayaan inaad kaydiso, maamusho, iyo hawlgasho xogta qaab fudud iyo habboon.

Complex Data Types - Objects and Arrays.
Complex Data Types - Objects and Arrays. 


Objects

Objects waxay yihiin qaab-dhismeed xogeed oo kuu oggolaanaya inaad keydiso xog la xiriirta magacyada iyo qiimayaasha. Qeexidda object waxay u egtahay sidan:

javascript

const person = { name: 'Mowlid', age: 30, occupation: 'Developer' };

Halkan, person waa object leh saddex sifo: name, age, iyo occupation. Mid kasta oo ka mid ah sifadaas waxay leedahay qiimo (string, number, ama string). Waxaad ka heli kartaa qiimaha sifada adigoo adeegsanaya magaca sifada:

javascript

console.log(person.name); // Mowlid console.log(person.age); // 30

Objects sidoo kale waxay taageeraan hababka si aad u sameyso waxqabadyada kala duwan. Tusaale ahaan:

javascript

const car = { brand: 'Toyota', model: 'Corolla', startEngine: function() { console.log('Engine started'); } }; car.startEngine(); // Engine started

Halkan, startEngine waa method ka mid ah object-ga car, waxaana loo isticmaali karaa in lagu fuliyo hawl gaar ah.

Arrays

Arrays waxay yihiin qaab-dhismeed xogeed loogu talagalay in lagu kaydiyo uruurin xog oo isku nooc ah. Arrays waxay ku jiraan sifooyinka iyo hawlaha isku midka ah oo u oggolaanaya inaad la shaqeyso xogta sida liis. Tusaale ahaan:

javascript

const fruits = ['Apple', 'Banana', 'Cherry'];

Halkan, fruits waa array ay ku jiraan saddex qaybood: Apple, Banana, iyo Cherry. Waxaad ka heli kartaa waxyaabaha ku jira array adigoo adeegsanaya index:

javascript

console.log(fruits[0]); // Apple
console.log(fruits[1]); // Banana

Arrays sidoo kale waxay taageeraan hawlo badan oo kala duwan sida push, pop, iyo shift. Tusaale:

javascript

fruits.push('Orange'); // Ku dar 'Orange' dhamaadka array-ga console.log(fruits); // ['Apple', 'Banana', 'Cherry', 'Orange'] fruits.pop(); // Ka saar 'Orange' console.log(fruits); // ['Apple', 'Banana', 'Cherry']

Isku Dhafka Objects iyo Arrays

JavaScript sidoo kale waxay kuu oggolaanaysaa inaad isku dhafdo Objects iyo Arrays si aad u sameyso qaabab xogeed oo adag. Tusaale ahaan, waxaad abuuri kartaa array ka kooban objects:

javascript

const people = [ { name: 'Mowlid', age: 30 }, { name: 'Amina', age: 25 } ]; console.log(people[0].name); // Mowlid

Halkan, people waa array ka kooban laba object, mid kasta oo ka kooban sifooyin name iyo age.

Gabagabo

Objects iyo Arrays waa noocyada xogta adag ee aasaasiga ah ee JavaScript, waxaana loo isticmaalaa in lagu kaydiyo loona maareeyo xogta. Objects waxay kuu oggolaanayaan inaad keydiso xogta magacyada iyo qiimayaasha, halka arrays ay kuu oggolaanayaan inaad kaydiso uruurin xog ah. Isticmaalka saxda ah ee noocyadan xogta waxay ka dhigi kartaa koodhkaaga mid hufan oo sahlan in la fahmo.

Previous Post Next Post