Your short example will also give the length of a string, or any other object that has a length property... so strictly speaking, the code is not equivalent at all.
Also, a shorter way to do the same thing (as the second example) would be:
Indeed it will give the length of a string. Even if a string behave like an array of characthers, it is not really an array as Array.isArray() will return false.
So yes the two code are not striclty equivalent. But it will do the job in a short and more elegant way.
And the way you showed is really nice, thanks.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Your short example will also give the length of a string, or any other object that has a length property... so strictly speaking, the code is not equivalent at all.
Also, a shorter way to do the same thing (as the second example) would be:
Indeed it will give the length of a string. Even if a string behave like an array of characthers, it is not really an array as
Array.isArray()
will return false.So yes the two code are not striclty equivalent. But it will do the job in a short and more elegant way.
And the way you showed is really nice, thanks.