Delving into arrays today with javascript. I have created two arrays
var items = ['Bread', 'Milk', 'Butter']
var calories = [10,20,30]
The idea is that the calories correspond to the item, so bread has 10 calories. And if I want to see the two arrays combining results then i call this
document.writeln(items[1] + calories[1])
I’m guessing theres a much more efficient way of doing this, but as a newbie I would appreciate any pointers in the right direction. Ideally I want to store all the info in one array
One way would be to use an object instead of an array:
There is a good article on MDN about working with objects in JavaScript that might be useful to you.