JavaScript打印数组到括号和引号的字符串 [英] JavaScript print array to string with brackets and quotes

查看:43
本文介绍了JavaScript打印数组到括号和引号的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var fruits = ["Banana", "Orange", "Apple", "Mango"];

如果我有上面的数组并希望将其输出到DOM中的用户 [Banana,Orange,Apple,Mango]

If I had the above array and wanted to output it to the user in the DOM as ["Banana", "Orange", "Apple", "Mango"]

最好的办法是什么这个?

What would be the best way to do this?

我试过 fruits.toString(); 输出为香蕉, Orange,Apple,Mango

推荐答案

使用JSON.stringify

Use JSON.stringify

JSON.stringify(fruits)

这篇关于JavaScript打印数组到括号和引号的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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