return a string from an array a of characters?
时间: 2024-03-14 12:47:55 浏览: 62
You can return a string from an array of characters by using the `join()` method in JavaScript. Here's an example:
```javascript
const arr = ['h', 'e', 'l', 'l', 'o'];
const str = arr.join('');
console.log(str); // Output: "hello"
```
In this example, we first create an array of characters `['h', 'e', 'l', 'l', 'o']`. Then, we use the `join('')` method to join all the elements in the array into a single string. The parameter passed to the `join()` method determines the separator between the elements. In this case, we pass an empty string `''` as the separator, which means that there will be no separator between the characters. Finally, we store the resulting string in the variable `str` and log it to the console.
阅读全文