Bit of a weird title, let me explain.
Take this:
let a = ['a', 'b', 'c']
function joining(){
console.log(a.join())
}
joining() // a,b,c
THE ABOVE IS JOINED
function joining(){
a.join()
console.log(a)
}
joining() // ['a', 'b', 'c']
THE ABOVE IS NOT JOINED
function pushing(){
a.push('d')
console.log(a)
}
pushing() // ['a', 'b', 'c', 'd']
THE ABOVE IS PUSHED
The first joining()
joins them correctly as I have called .join()
on the array.
However, the second one I have called joined on it and then tried to log it but it displays the original.
However I did exactly the same with the push()
method and that changed the original array. how can I tell what methods will change the original array and which wont or is it just a case of learning each method?