I'm trying to give the array projects
a global scope and call the array and use the array in the function.
var projects = [{ //GLOBAL SCOPE
label: "Appels",
icon: "./Appels".png",
href: "./Appels".html"
}, {
label: "Pears",
icon: "./Pears.png",
href: "./Pears.html"
}];
$(function() {
var projects = [{ //LOCAL SCOPE
label: "Appels",
icon: "./Appels".png",
href: "./Appels".html"
}, {
label: "Pears",
icon: "./Pears.png",
href: "./Pears.html"
}];
});
How can I make a projects array a global var and assign it in the function?
EDIT: I tried to remove the var
from var projects
inside the function.
When I tried calling it from another page. (When creating 2 array's like the code above it works fine without an error.)
With:
var randomItem1 = projects[Math.floor(Math.random()*projects.length)];
I'm getting this error:
Uncaught ReferenceError: projects is not defined
When creating 2 array's like the first piece code it works fine without an error. I want 1 array of projects, so it is easier to edit.