12

Can anyone tell me the exact difference between join() and toString() and valueOf()in Javascript. When and at what situation we need to use them?

4

1 回答 1

26

toString是一种方法,您不仅可以在Arrays 中找到,而且可以在每个对象中找到。

join允许您将Array对象的每个元素转换为字符串,并使用分隔符连接在一起。它的行为就像toStringfor Arrays,但你也可以指定分隔符:

var classes = ["first", "second"];
classes.join(" ");    // "first second"
于 2013-06-24T07:08:15.497 回答