I am trying to map two data "points" together, which do not really have anything in common. I have an array which contains images at certain positions, within the array. I also have a variable that can contain various values (1, 2 or 3), and I want to map the array position (1, 2 or 3) and the variable value, to show the image that is in the specific array position.
<script>
var images = new Array()
images[1] = 'image/position/in/folder/image.jpg';
images[2] = 'image/position/in/folder/image.jpg';
images[3] = 'image/position/in/folder/image.jpg';
var var_name = somedata
/*----here I need help or guidance----
jQuery(document).ready(function() {
var jQuerydiv = jQuery(".image_div");
jQuery.each(images, function(i, val) {
jQuery("<img />").attr("src", val).appendto(jQuerydiv);
});
});
/*------guidance/help ENDS------------
<script>
<div class="image_div"></div>
This script throws all images in the array "images" to div "image_div". I want to only show the image in the array, which position (1, 2 or 3), matches the value of variable var_name, which can contain 1, 2 or 3.
Anything obliged.