How to compact hard-coding into arrays and for loops in Javascript? -
I have written a function to display some pictures on my site:
function Draw_things () {var talker = new array (10); Chief Arrary [0] = {thingTitle: "First thing", Object Description: "Random word", cheese SRC: "Folder / 0.ZipGi", the thing is HREF: "#", Chasertating: '0', Dimensions of things: '644 The object is [1] = {thingTitle: "second thing", item description: "random word", cheese src: "folder / 1.jpg", the thing is HREF: "#", cheerising: '0', the dimensions of the cheeses: '644'}}
I have done the above code with 10 elements with hard work.
However, I am trying to use a small code like this for loop:
function draw_things () {var thingArray = new array (10) ; Var title = ["first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninith", "tenth"]; Var str = "folder /"; Var toStr; Var talk SRCSR; Var thingTitleStr; (Var i = 0; i & lt; thingArray.length; i ++) {toStr = i.toString (); ThingStr = str + toStr + ".jpg"; ThingTitleStr = Title [i] + "Thing"; Talk: [i] = {thingTitle: thingTitleStr, Objects: "Random word", Cheese SRC: mem STR, talk HREF: "#", is talking: '3', Dimensions of things: '644'}}
The problem is that, there are some .gif files out of those pictures. For example, 1. GIF and 6.GIF while all others are .jpg
How will it be known about facing this problem?
Thanks
I will create an array of files containing GIF extension. And then use it to choose between .jpg
and .gif
... var gifs = [1, 6] Done; ... for (var i = 0; i & lt; thingArray.length; i ++) {... thingStr = str + toStr + (gifs.indexOf (i)! = -1? ".gif": ".jpg"); ...}
Comments
Post a Comment