I've look at a few other posts but am still slightly confused about using arrays within arrays.
So I've created my array as below:
var pagesArray = [
{
category: 'pages1',
pages: [
'firstPage1',
'secondPage1',
'thirdPage1',
'fourthPage1'
]
}, {
category: 'pages2',
pages: [
'firstPage2',
'secondPage2',
'thirdPage2',
'fourthPage2'
]
}
];
Now I want to be able to search the array and find if a string exists in it. If it does, I want it to return the value of what position it is.
E.g.
jQuery.inArray('secondPage1', pagesArray)
to give the result:
pagesArray[0][1];
I'm not sure if I've written the array wrong and if I'm using inArray correctly. If I try to alert(pagesArray[0][1]); it gives a value of undefined. What am I doing wrong here?
console.log(pagesArray), then you know if the array is indeed correct.pagesArray[0][pages]is what I think you'd need.