I've got a script that allows me to search my Google Sheets doc and returns a row of items in an array. I've console.logged the results see image but I can't workout how I only (alert) the 6th item?
I know this is basic stuff but I can't work it out on my own.
Here's my code
function showPrice(el, arrayOfArrays, index) {
const results = arrayOfArrays.filter(r => r[0] === "Dog");
alert(results[6]);
}
I get undefined?
Your filter returns the outer array since its first array's 0th entry is Dog
The outer array's length is 1
So perhaps you want to show the 6th entry of the nested array returns in the filter?
const arr = [
["Dog", "Colorbyte", 40, 700, 1, 2, 3, 4]
]
function showPrice(el, arrayOfArrays, index) {
const results = arrayOfArrays.filter(r => r[0] === "Dog");
console.log(results.length)
console.log(results[0][6]);
}
showPrice(null,arr,null)