I have the following js code.
When I call the arrHelper
function with the string "martin" I have noticed that my console.log is only showing the first three characters i.e ["m", "a", "r"] but not the full ["m", "a", "r","t","i","n"]. This happens even when I change the argument to a different name I am not getting the full converted array. This does not happen if I don't use the function Array.isArray()
.
let arrHelper = (str) => {
let splittedStr = Array.isArray(str) ? str : str.split('')
console.log(splittedStr)
return (
splittedStr.map((v, i, a) => {
return (
a.splice(-1)
)
})
)
}
console.log(arrHelper("martin"));