+ 5
Can anyone explain me simple meaning of array and how it can be used.
Please want in simple ways that I can understand
22 ответов
+ 19
Array is a container that holds fixed number of values of the same type, each having a numerical index.
+ 13
Suppose you have to store values of 5 student marks then you can do this by the following normal variable declaration , cannot it?
var s1 = 67;
var s2 = 45;
var s3 = 77;
var s4 = 87;
var s5 = 55;
but when you have to store marks of 100 students then what will you do, let's see
var s = new Array(100); //Declared an array having size 100
var s[0] = 67; //Storing in first element
var s[1] = 45;//Storing in second element
var s[2] = 77;
var s[3] = 87;
var s[4] = 55;
var s[5] = 66;
var s[6] = 84;
...
....
.....
var s[99] = 56;//Storing in last element
Now storing values on and on is too frustration na,
let's have a look -
/////////////////////////////////////////////////////////////////////
for(var i=0;I<s.length;i++)
{
var marks = prompt("What's Marks of " + i+1 + " Student ?")
s[i] = marks;
}
////////////////////////////////////////////////////////////////////
I hope this is really amazing illustration on the ground of skill.....OK Dear Miller, isn't it ?
A/c to Definition
Array is an object in Java Script that is used to store many values of same data type in a single variable.
+ 4
An array is a data structure that contain data of the same type and occupy contiguous memory spaces.
+ 3
An array can be defined as a collection of values of similar data types..
You can declare an array by first typing the data type and then putting it in a variable
For example:the
int a[]= new int[10];
The number within the big brackets is the size of the array i.e the number of elements the array is holding..
Like if I found this helpful..
+ 3
you can think array as a variable or a container with multiple values and each value can be accessed with an index number
+ 2
array is a collection of values with similar datatypes or collection of homogenous data
+ 2
array is a collection of elements of similar datatype
in java array is declared as for giving dynamic values to array elements....
datatype array_name []=new datatype [size_of_array]
for static values of array elements....
datatype array_name []={1,2,3,4}
+ 2
An array is simply a list of objects or variables. If there were no arrays, then each array object would be a separate variable. It can be used to sort things together. You can make a lot of things with arrays.
+ 2
A book is an array containing a set number of items, ie: pages. These pages all go in order, one after another. There is a definite beginning and end.
+ 1
arrays are identified by [ ] . Ie.. Int a[0] =5.
for storing large number of elements of the same datatype either be int or float etc.
rather than declaring one by one element with that same data type .
+ 1
An array is a data structure!
+ 1
A variable is an allocation of memory ...a address in memory ....a value is a name pointing to that address...an array is a data structure that allows to aggregate variables together using a value key pair
+ 1
when you declare an array, the computer knows to set aside a number of memory locations equal to the size you declared. it knows they are a list of sorts. this ability to tell the computer to make a list is called a data structure. so if you say int [ ] array = array int (5), the computer sets aside 5 memory locations that will all hold integer values. this way you don't have to add them all one at a time.
+ 1
let's say it is a box with many compartments with different numbers. In each compartment, you can keep different things and ask the computer to take out a thing for you by telling it the compartment number.
+ 1
Array would be like a storage bin with many different compartments containing the same types of things. The first compartment starts at zero, the second 1 and so on...
+ 1
An Array is a linear collection of data of same type in classical languages like C/Java. But in JavaScript an Array is a Object and capable of holding any type of data!
+ 1
An array is like one of those "pill sorters" that older folks use to keep their medication(s) straight.
There is a separate pocket for each 'day'. (in this case the "day" is the "index")
Assuming that Sunday is day "0".
So an array of:
$pills = array (sunday => "cholesterol", monday => "Blood Pressure", tuesday => "viagra" );
echo $pills[sunday] ~ would return "cholesterol"
echo $pills[tuesday] ~ would return "viagra" (party day!!)
+ 1
Array Is Nothing But Collection Of Multiple Values Of Similar Data type
it is Used when Large Number of Data is To Be Executed
0
when you have avalue you can store it in a variable. If you need to store more values ex. 100 values you can create an array instead of 100 variables
int x=3; //variable
int arr []={4, 5, 6, 8, 9,........ } //arrsy of values
0
suppose you have three bottles of cola, juice and gatorade, and in order to handle it all at once you need a box for container. but you are thirsty and you need to drink water, youll take a look and get the water, but then you worked out and needed gatorade and so you take a look and get gatorade and so on.
the data is the three bottles, the array is the box container. in order to access it you need to take a look at its position. once you get it you can access the data.
basically it holds a data that can be reused in every function of your program provided it was set as public. so you don't need to initialize it everytime, easiest way to get a set of data thru for loops or any other loops.