小编nem*_*man的帖子

比较两个阵列并将其连接

我有两个数组as typesdefaultTypes。我需要显示types 默认值array defaultTypes

 const types = [
    {
        Id: 2,
        Name: 'Some value here'
    },
    {
        Id: 3,
        Name: 'Some value here'
    },
    {
        Id: 4,
        Name: 'Some value here'
    }
 ];

 const defaultTypes = [
    {
        Id: 1,
        Name: 'Default value 1'
    },
    {
        Id: 2,
        Name: 'Default value 2'
    }
 ]
Run Code Online (Sandbox Code Playgroud)

如果in types中不存在某些默认类型(在这种情况下,Id:1在types数组中不存在)。我需要在types数组中添加该对象。预期结果将是:

 const expectedTypes = [
    {
        Id: 1,
        Name: '-'
    },
    {
        Id: 2,
        Name: …
Run Code Online (Sandbox Code Playgroud)

javascript arrays foreach object filter

0
推荐指数
1
解决办法
65
查看次数

从JS数组创建字符串

我有阵列:

const arr = ["This is Sparta", "Yes it is", "Hello"];

我想要像这样的字符串输出:

const str = "This is Sparta, Yes it is, Hello"

所以,在数组中的每个逗号之后我需要在字符串中使用break line.

javascript arrays string

-2
推荐指数
1
解决办法
127
查看次数

标签 统计

arrays ×2

javascript ×2

filter ×1

foreach ×1

object ×1

string ×1