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
Use Join like this
person.address.join(',')
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(', '));
person.address.join(','); is not enough for you because you also want to a space.so person.address.join(', '); is correct.You try this.
alert(person.address.join(', '));
Here is detail. http://www.w3schools.com/jsref/jsref_join.asp
person.address.join(', ')