ES6将数组映射到不带逗号的字符串 [英] ES6 map array to string without comma

查看:762
本文介绍了ES6将数组映射到不带逗号的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将错误列表映射到我将在工具提示中显示的列表中。添加了列表,但是在每个li元素之间添加了

I am trying to map a list of errors into a list that I will show in a tooltip. The list added, but there's a , added between every li element.

我想这是因为这基本上是 errors.map(error => ...)。toString()最后。有没有想法如何在没有添加逗号的情况下映射错误数组中的字符串?

I guess this is because this basically does errors.map(error => ...).toString() in the end. Any ideas how I can map the strings in errors array without having this comma added?

data-tip = {`
  Precisa de corrigir os seguintes problemas antes de publicar o anúncio:</br>
  <ul>
    ${errors.map(error => `<li>${error}</li>`)}
  </ul>
`}


推荐答案

.toString()使用 Array.prototype.join 方法将数组转换为字符串。默认情况下, .join 方法使用来加入元素。您可以用 .join('')替换 .toString()

.toString() of the array object uses Array.prototype.join method for converting the array into a string. The .join method by default uses , for joining the elements. You can replace the .toString() with .join('').

这篇关于ES6将数组映射到不带逗号的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆