-
Notifications
You must be signed in to change notification settings - Fork 0
#13 π Javascript Array
*****************************Tutorial Start π₯ ********************************
Revise previous topic
Varaible ki help se hum data store karte hai and statement and function ki help se humko processing karte hai data pe.
But variable me hai kuch like:
<script>
//variable problem example
let a = 5;
console.log(a)
/* too memory block me a ki place pe 5 value store ho gyi hogi */
/* but agar hum fhir se a ki jagah koi aur value store karna chaye too ab 5 ki jagah 6 aajega
matlab ki value override ho gyi
*/
/* variable matlab aik baar me aik value */
a = 7;
console.log(a); //output 7
</script>
Agar humko aik hi variables me multiple values rakhna hai, like a variable ke andar hum 10+ values rakh le (10,20,30, 40 ...100) And,
- a ke andar hum 10 marks rakh le
- yaa a ke andar hum 10 student ke name rakh le
Isko hum array ki help se karte hai, hum array ki help se aik hi variable me multiple values ko store kar paate hai.
<script>
//array example
let b = [5, 6, 7, 8, 9, 10]
console.log(b) /* isko karne se pura ka pura array print ho jayega kyu ki b me
bhut saari values rakhi hai
*/
</script>
- Array ki indexing hoti hai
- Ab ye sab values elements hai,and ab inki indexing hogi jo ki 0 se start hoti hai 0,1,2,3 and so on.
- Indexing islia kyu ki isko aik hi variable point kar rha hai.
Like this,
Index/Position Values
0 -> 5
1 -> 6
2 -> 7
3 -> 8
4 -> 9
5 -> 10
<script>
//array indexing example continue...
console.log(b[2]); //output 7
console.log(b[5]); //output 10
</script>
- Array **
In javascript array data-type is not fixed.
Hum aik hi array me mixed type ka data rakh sakte hai like: number, name, floatingpointnumber, object ko bhi store kar sakte hai. Type fixed nhi hai.
<script>
//array properties example
//Example 1
let arrName = [45, "adarsh", 49.1000, "shubh"]; /* its is valid array,
array me heterogenous element allowed hai, alag alag tarike ke elements aik hi array
me allowed hai.
*/
console.log(arrName);
//Example 2
/* let suppose humko bus floating points values 49.1000 print karna hai, soo aisee karege */
console.log(arrName[2]);
</script>
But c and java me array ka type fixed hota hai.
Size of array is also not fixed.
<script>
//size of array not fixed properties example
let sizeArr = [1, 20, "adarsh", 59, 23]; //not of elements/size is 5
console.log(sizeArr);
console.log(typeof sizeArr)
/* and agar humko aik aur elements add karna hoga baad me too aisee karege */
sizeArr.push("shubh"); //adding 6 elements "shubh" string type.
console.log(sizeArr); //output 6 elements added in last
/* hum run time me elements add kar sakte hai too size apne aap change ho sakta hai automatically. */
/* and type bhi fixed nhi hai javascipt array ka */
</script>
ye sab function array ke object se milte hai. Given Below:
- concat
- constructor
- FindIndex
- Filter
- indexOf
- FloatMap
- forEach
- join
- reduce
- splice
and many more....
*****************************Tutorial End π ********************************
FOllow me on Github