I am a novice. Recently, I came across such a code when I was reading a book about javascript
. I don"t really understand it. The code for apply
binding is as follows:
const concatAll = (array) => {
let result = []
for (let value of array) {
result.push.apply(result, value)
}
return result
}
let letters = [["a", "b"], ["c", "d"]]
console.log(concatAll(letters)) // ["a", "b", "c", "d"]
to put it simply, concatAll
this function can convert a nested array into an array. What I don"t understand is how line 4
of the code works, and how the method apply
works. The previous knowledge about this
is also a little confused, not particularly understood. I hope someone can give a detailed answer
Thank you!