I'm currently looping on an object in javascript and successfully got what I need from the _source level. My problem now is that there is another array under color inside _source.
Currently, console.log(searchResult); gives me this object:
1
_source
color
1
color_type
type
name
id
I can access type and color because they're on the _source level, but I need to access color_type which is part of another array within color and it needs to obviously be the info contained in my originally indexed element.
Do I need to create a new loop here to access the color info?
let searchResult = response.hits.hits;
console.log(searchResult);
for(let i = 0; i < searchResult.length; i++) {
//This line displays the name.id properly
document.getElementById("name").value = searchResult[i]._source.type.name.id;
//this line gives undefined
document.getElementById("color").value = searchResult[i]._source.color[i].color_type;
})
}
_source.coloris an array that can contain multiple elements, but ultimately it depends on what you are trying to do.1the only index insidecolor?