Interesting and accurate, arrays and strings are clearly not the same.
I think the confusion may come because both arrays and strings share some methods and properties with the same name, and we can do some "array-like" things, like:
length concat() str[0] -- character position access ( though, the correct approach should be str.charAt() )
Also, arrays are mutable and strings aren't. so we can't do this:
str[1] = 'stuff'
Also, when using the native constructor, for instance, new String('Sup dude') each character is numerically indexed (like arrays), but in this case, even though we're using the built-in native constructor, it is not creating a string, instead, it creates an object. So, when using the string properties - length, concat, etc - JS implicitly does this boxing for us( under the hood it uses the String() native ). So we need to do str.toString() in order to get the actual string.
Thanks pentacular and Diego, these are really great points that I neglected to touch on. I'll add a bit into the tutorial and video to emphasize the distinctions.
Tech Lead/Team Lead. Senior WebDev.
Intermediate Grade on Computer Systems-
High Grade on Web Application Development-
MBA (+Marketing+HHRR).
Studied a bit of law, economics and design
Location
Spain
Education
Higher Level Education Certificate on Web Application Development
Those are language specific methods, in fact theoretically, strings have length while arrays have size, you can concat strings while you join arrays and string[i] breaks up on most languages for obvious reasons.
It's a comparison of whole different data structures where I don't want to involve at all (that's all already wrote about) but i feel the need to clarify this.
Also an array of chars is not the same than a string, if you want to sort, compare or change values from a string for a given output you'll need to cast it into a char array first. That's basic cryptography like Caesar's Cryptography for example.
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.
Interesting and accurate, arrays and strings are clearly not the same.
I think the confusion may come because both arrays and strings share some methods and properties with the same name, and we can do some "array-like" things, like:
length
concat()
str[0]
-- character position access ( though, the correct approach should bestr.charAt()
)Also, arrays are mutable and strings aren't. so we can't do this:
str[1] = 'stuff'
Also, when using the native constructor, for instance,
new String('Sup dude')
each character is numerically indexed (like arrays), but in this case, even though we're using the built-in native constructor, it is not creating a string, instead, it creates an object. So, when using the string properties - length, concat, etc - JS implicitly does this boxing for us( under the hood it uses the String() native ). So we need to do str.toString() in order to get the actual string.Thanks pentacular and Diego, these are really great points that I neglected to touch on. I'll add a bit into the tutorial and video to emphasize the distinctions.
You're welcome. :)
You did a great job Jake, we're all in this endless learning process! So keep up the good work man! :-)
Appreciate the kind words!
Those are language specific methods, in fact theoretically, strings have length while arrays have size, you can concat strings while you join arrays and string[i] breaks up on most languages for obvious reasons.
It's a comparison of whole different data structures where I don't want to involve at all (that's all already wrote about) but i feel the need to clarify this.