modifying Array and outputting the modified version
I want to output all the arrays with modified version, I want to put ? in the end of usernames and ! in the end of items
Why does it output user.username.map is not a function?
5 Replies
.map
is a function that exists on arrays, user.username
is a string
this should be this
Or even just this
i thought you have to loop through the username
specifically
like what i did on looping all through the array
it's just a string, there's nothing to loop over because it's a single value
you technically can loop over a string if you slice it first, but that would add a ? in between every character
if your array items looked like this:
that'd be different, but the way you have it now you cannot loop over the username
oh when i did the map(user) im already in the array, so thats why i cannot loop through the usernames using map, items.map(item) is working because its an array
well, you can't loop through the usernames using map ever, even if you just access it by using array[0].username, but yes, you're already looping over the users and that's why you have access to the username right away
and correct about items.map, that works because it's an array