arrays in jquery code example

Example 1: how to take create array using jquery

var length = 5;
var array = [];
var i = 0;

for (i = 0; i != length; i++){
  array.push(i)
  //array.push is used to push a value inside array
} 

console.log(array);

//console.log is used to check array value inside your console

Example 2: jquery create array

var colors = ['red','blue','green'];

/*// OUTPUT
---------------------------*/
console.log(colors[1]); // Outputs 'blue'

Example 3: javascript associative array

/*
Associative array in javascript
There are multiple programming supports array and arrays is having different types i.e
1. Index Array
2. Associative Array
3. Multidimentional Array

But as question asked javascript does not support associative array with named indexes.
Javascript only use numbered indexes in arrays.
*/

Example
var studentDetail = [];
studentDetail[0] = "Code";
studentDetail[1] = "Grepper";
studentDetail[2] = 24;
studentDetail[3] = 'Mumbai';
var x = studentDetail.length;     // studentDetail.length will return 4
var y = studentDetail[1];         // studentDetail[0] will return "Grepper"

/*
I hope it will help you.
Namaste
Stay Safe Stay Home
*/