MODULE3: ARRAYS WITH BABY LOOPY part1

Qaybta Xirfada Sayniska iyo iwm

Moderators: Moderators, Junior Moderators

User avatar
afisoone
SomaliNet Super
SomaliNet Super
Posts: 5509
Joined: Wed Jul 22, 2009 9:46 pm
Location: We all want to become president even though Amisom controls Mogadishu

MODULE3: ARRAYS WITH BABY LOOPY part1

Post by afisoone »

The best part of the any language you learning is array. It is every important part.

Every game designer familiar with this loop..

let's have an array first.

let somalistate=['puntland','Somaliland','Jubaland','galmudug'];

now let is loop......
<script type="text/javascript">

let somalistate=['puntland','Somaliland','Jubaland','galmudug'];
for(let i=0; i<somalistate.length;i++)
{
daabac=somalistate;
console.log(daabac);
}



</script>


It will display
puntland Somaliland jubaland


But there is similar way you can do it using..... Foreach and call back function

here is and example..

Somalistate.forEach(sooDaabac);

SooDaabac is a call back function that will display the result. Let's build the the function now..

somalistate.forEach(sooDaabac);
function sooDaabac(daabac){
console.log(daabac);
}


As you can see we can use that call back as template to display many arrays..... you can create another array and that function it will display for you. It is what forEach does..
we will continue with array...
  • Similar Topics
    Replies
    Views
    Last post

Return to “Careers - Engineering, Science & Computers”