0
var person = {  
address: [
    '308 Congress Street',
    'Boston',
    'Massachusetts'
]
}

How to insert Array join method in "address" and display all Array item.

The result would be like this: 308 Congress Street, Boston, Massachusetts

1
  • person.address.join(', ') Commented Jan 17, 2017 at 4:33

4 Answers 4

1

Use Join like this

person.address.join(',')
Sign up to request clarification or add additional context in comments.

1 Comment

Happy to Help! :)
0

Like this..use array's join() method.join() method joins all array elements into a single string.

var person = {  
address: [
    '308 Congress Street',
    'Boston',
    'Massachusetts'
]
}

alert(person.address.join(', '));//OR alert(person['address'].join(', '));

3 Comments

glad to help you.enjoy and best of luck ahead.
try using both ways.
just person.address.join(','); is not enough for you because you also want to a space.so person.address.join(', '); is correct.
0

You try this.

alert(person.address.join(', '));

Here is detail. http://www.w3schools.com/jsref/jsref_join.asp

Comments

0

If you want the last index of the address array to be the combined values, just do...

person.address.push(person.address.join(', '))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.