peter456 peter456 - 1 year ago 65
CSS Question

how to write images to an array

var products =[
{ "image.src =": "images/shopcart/jello.jpeg", "name": "Lusicious Jello Mix", "description": ["Very Elegant", "Trending item", "Come in Purple"], "price": 80.65 },
{ "image": "images/shopcart/desk.jpeg", "name": "Tarnished Standing Desk", "description": ["Modular", "Works for both Tall and Loud People", "Smells like Productivity"], "price": 1654.99},
{ "image": "images/shopcart/grenade.jpeg", "name": "Hand-made Hand Grenades", "description": ["Such gift!", "Much boom!", "Very safe for kids"], "price": 10.44},
{ "image": "images/shopcart/cookie.jpeg", "name": "Pan-fried Cookie Dough", "description": ["Chocolate", "Family-size", "Hot Mess"], "price": 16.99 },
{ "image": "image/shopcart/hanger.jpeg", "name": "Fancy Dress Hanger", "description": ["Keep organized", "On Sale"], "price": 67.32 },
{ "image": "image/shopcart/mustache.jpeg", "name": "Snarky Britsh Mustache 3-Pack", "description": ["Sharing is caring!", "Hugs not drugs", "As seen on 'So You Think You Can Dance - Nigeria!'"], "price": 1.99 },

Looking for the correct syntax for these images within the array. I know src has to be somewhere in it just not sure where or how. Thanks.

Answer Source

You write literal objects in javascript which is a dynamic language. You are not obligated to use a specific format, you just use one that fits you.

I suggest using the following

var products = [
{ "name" : "Milk",
  "image": {
 "src": "path/to/my/milkpic",
 "alt": "Milk photo"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download