Arrays

Wa maxey Arrays ? array wa inaad hal (1) variable ku keydiso macluumaad kale duwan. Macluumaadkaas waxa u noqon karaa kuwa isku data-type ah sidokale wa ey kala duwanaan karaan.

 

Array Syntax

				
					const variableName = new Array("data1", data2, data3....);
				
			
 
Advantages of Array / Faaidooyinka Array
24 data-type keedu wa Number, sidokale “Ahmed” data-type kiisu wa String, hadii aad rabto inad variable ku shubto labadan 24 iyo “Ahmed” waxey noqoneysa inaad u sameyo labo(2) variable oo kala duwan.

Array waxey ku ogolaaneysa inaad hal (1) variable iskula keydiso 24 iyo “Ahmed”. 
 
Example/Tusaale

With out Array

				
					const age = 24;
const name = "Ahmed";
				
			

 

With Array

				
					const details = new Array(24, "Ahmed");
				
			

 

Different types of Array / Noocyada Array

Array Function
				
					const details = new Array("Ahmed", 24);
				
			
 
Array literals
				
					const details = [24,"Ahmed"];
				
			

 

Aqriste waxaa jiro methods tiro badan oo ku dhex jiro Arrays, waxeyna no suuro galiyaan inaan Array wax ku darno, wax ka reebno, sidokale waxey naga caawiyaan inaan ogaano waxa ku dhex jiro Array. 

Tusaale

hadii aad rabto inaad wax ku darto Array waxa jiro method kaa caawinayo shaqadas.

				
					console.log(details); // Before Ouput: [ 24, 'Ahmed']
details.push("Yare");
console.log(details); // After Ouput: [ 24, 'Ahmed', 'Yare' ]
				
			

method ka push() waxa uu oga darayaa details qeebta dambe ama meesha ogu dambeyso.

Sidokale wax ayaad ka jari kartaa Array.

				
					details.push("Yare");
console.log(details); // Before Ouput: [ 24, 'ahmed', 'Yare' ]
details.pop();
console.log(details); // After Ouput: [ 24, 'ahmed']
				
			

method ka pop() waxa uu delete garenaya midka ogu dambeeyo.

 

Conclusions

Aqrinste waxaan rajeenaya inaad wax badan ka faaidey qormadaan.

Next Lesson >

Share