'Object that contains an array of arrays, how to remove object so it's only an array of arrays
I have an object that contains an array of arrays. I would like to remove the object so it's only an array of arrays. Is there a way in JavaScript to do this or am I out of luck? I'm using Puppeteer to scrape a page and return all the text after mapping through a set of elements. I've already written a function to seprate it into the arrays I want but Puppeteer returns it as an object which I don't want. The object it returns looks like this
UPDATE
Turns out it's returning a promise which is an object. So the result that I get when I log to the console is
Promise {
[ [], [], []... ]
}
So I guess my new question is how do I get only the result of the promise.
data = {
[
[], [], []...
]
};
I would like it to look like
data = [
[], [], []...
]
Puppeteer function
const getText = async (data) => {
const browser = await puppeteer.launch({ headless: true })
const page = await browser.newPage()
await page.goto(data.URL, { waitUntil: 'networkidle2' });
const options = await page.$$eval('table[class="data-table"] > tbody > tr > td', (options) =>
options.map((option) => option.textContent)
);
await browser.close();
const finalData = createGroups(options, 228);
// the puppeteer function returns each texContent as a single array, meaning the page
// I'm scraping returns 1140 arrays, I want each array in my final product to contain 5
// elements so I did 1140/5, that's how I got 228
console.log(finalData);
}
createGroups function
const createGroups = async (arr, numGroups) => {
const perGroup = Math.ceil(arr.length / numGroups);
const finalArr = new Array(numGroups)
.fill('')
.map((_, i) => arr.slice(i * perGroup, (i + 1) * perGroup));
return finalArr;
}
Or is there is a way to just extract that large array which contains the smaller arrays and put that into it's own variable? The way to do it with arrays would be LargeArray[0] but I don't know how to do that with objects.
Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
