If you always want to extract an RGB value, and thus have 3 values in your colors array. You could do something like this:
const colors = [[31236780195925], [], [], [], [], [31236780163157], [], [], [31236780228693], [], [], [], [], []];
const indexes = [];
colors.forEach((color, index) => {
if (color.length > 0) {
indexes.push(index);
}
});
const red = colors.slice(indexes[0], indexes[1]);
const green = colors.slice(indexes[1], indexes[2]);
const blue = colors.slice(indexes[2]);
In case you want a more dynamic approach. You could loop over your colors array again and use those indexes to create a new nested array:
const slicedColors = [];
colors.forEach((color, index) => {
if (color.length > 0) {
const nextColorIndex = indexes[indexes.indexOf(index) + 1];
slicedColors.push(colors.slice(index, nextColorIndex));
}
});
const red = slicedColors[0];
const green = slicedColors[1];
const blue = slicedColors[2];