The async/await function search returns an object similar to:
[
{
"title":"page title",
"url":"/page/url/index.html",
"content":"blah blah blah"
},
...
]
I need to push each object from val into the array, but when I push using:
results = [];
search(input).then(val=> results.push(val));
I get a nested array similar to (I want to the object entries to be top level in the array):
[
[
{title:"...", url:"...", content:"..."},
{title:"...", url:"...", content:"..."},
]
]
So I tried a for in the arrow to push each entry in the object into the array, but that didn't seem to work.
results = [];
search(input).then(val=> for(i in val) {results.push(val[i])});
results = val? although I don't really see a purpose of doing this as you'll only be able to access the populated version ofresultsonce your promise has resolved, such as in the.then()callback, so you might as well just usevalsearch(input).then(val=> [].concat(results, val));