angular - 需要返回多个数组任何数据类型
问题描述
var a = ["A", "|" , "B" ,"|", [],"|",{obj:"Ashut"},"|",["ashu"]];
我需要这样的输出:
A | B | [] | {obj:"Ashut"} | ["ashu"]
我试过这样:
a.reduce(function(item, index){
return item + index;
});
但没有得到正确的输出。
解决方案
尝试这个 :
// Input array
var a = ["A", "|" , "B" ,"|", [],"|",{obj:"Ashut"},"|",["ashu"]];
// convert objects into string
var b = a.map((item) => {
if (typeof item === 'object') {
item = JSON.stringify(item);
}
return item;
});
// join the array
var res = b.join(' ');
// result
console.log(res);
推荐阅读
- angular - 离子电容器文件使Android上的应用程序崩溃
- apache-spark - 根据另一个数据集的 Min & Max 属性对数据集进行分区
- ms-access - 保存的访问查询随机截断为“SELECT;”
- python - python中'pop'的目的是什么?
- android - 调整FrameLayout大小不显示所有孩子android
- python - 是否可以在 mongodb 中使用通配符作为字段名称?
- database - 有没有办法在基于 m1 芯片的 mac 中运行 clickhouse?
- javascript - 有没有办法存储数组的索引并取回它的值?
- reactjs - 如何使用 react-redux 保存当前用户数据?
- javascript - 在 JSP 中,我从包含转义双引号的请求中读取了一个 JSON 字符串值,并且它失败了,就好像它们没有被转义一样