My findings on the Object type vs the array type using the each function and the alert working now on both !
in Using jQuery
•
11 years ago
Please note:
I do ask a quick question about a type function and example of it at the end of this posting !
___________________________________________________________________________
The following are some of the things i have been able to figure out so far there are two type
of structures that i need to address one is the object and the other is the array in both cases
i have been able to get the each() to loop through and display alerts to the screen with
the data contain in both.
of structures that i need to address one is the object and the other is the array in both cases
i have been able to get the each() to loop through and display alerts to the screen with
the data contain in both.
The object type you will see has a { } with the data contain inside the structrue I will first
address the object structure below.
var map = {'name': 'Fred Bloggs', 'firstName': 'Fred', 'lastName': 'Bloggs', 'headLine': 'Fun Maker'};
var map = {'flammable': 'inflammable','duh': 'no duh'};
The Array structure is the following
var arr = [ "one", "two", "three", "four", "five" ];
You will see the array structure has [ ] with the data inside the structure or brases as you see above.
___________________________________________________________________________________-
Now look at the loop each syntac of the object you will see the function works on a key and value pairs and
if you look at the array syntac of each you will see the function works on a index and value pairs.
if you look at the array syntac of each you will see the function works on a index and value pairs.
Now I will show below the object structure that seems to work fine now !
// Objects
var map = {'name': 'Fred Bloggs', 'firstName': 'Fred', 'lastName': 'Bloggs', 'headLine': 'Fun Maker'};
$.each(map, function(key, value) {
alert(key + ': ' + value);
// alert("Do I HAve a mesgage :");
});
____________________________________________________________________________________
Next I will show below the Array structure that seems to work fine now !
// Array
var arr = [ "one", "two", "three", "four", "five" ];
$.each(arr, function(index, value) {
alert(index + ': ' + value);
// alert("Do I HAve a mesgage :");
});
______________________________________________________________________________
I my script I wanted to use the array structure and now that works fine and even the
alert seems to work also and shows the values. I changed the following to my array
which was called mydataarray as you see below.
alert seems to work also and shows the values. I changed the following to my array
which was called mydataarray as you see below.
$.each(myDataarray, function(index, value) {
alert(index + ': ' + value);
// alert("Do I HAve a mesgage :");
});
Now is that all being said I can move on with my project which will be a lot easyer going
forward since i now have a base line to work from.
______________________________________________________________________________
My Question ?
If anyone knows away to use JQuery and test the type of variable being a object or array is
there a type function in Jquery that might be useful information for me ?
there a type function in Jquery that might be useful information for me ?
_________________________________________________________________________________
THANKS for all the help
Frank H. Shaw
1