Answer the question
In order to leave comments, you need to log in
How to make an array from the console?
I'm kinda dumb already. How from this
console.log(1)
console.log(2)
console.log(3)
console.log(4)
console.log(5)
[1, 2, 3, 4, 5]
Answer the question
In order to leave comments, you need to log in
Your Wishlist can be done with one simple expression:
const consoleArray = Object.keys(console).filter(
k => typeof console[k] === 'function'
).reduce(
([cnsl, acc], key) => [Object.assign(cnsl, {
[key]: (original => (...args) => (
acc.push(...args),
original.call(cnsl, acc)
))(cnsl[key])
}), acc],
[console, []]
)[1];
Have you confused anything? maybe vice versa?
let arr = [1, 2, 3, 4, 5]
function getConsoleLog(arr){
for (const i = 0; i < arr.length; i++){
return console.log(arr[i])
}
}
getConsoleLog(arr);
no way, the console is a stream (actually not, but conditionally it can be considered that it is), what is output to it is not saved anywhere,
if it’s true for some reason you need to do this, then make a wrapper function console.log
consoleArray = []
function log(xyi) {
consoleArray.push(xyi)
console.log(xyi)
}
log(4)
log(5)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question