账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    数组中如何按照规则筛选对象?
    44
    0
    const router = [
        {
            path: '/hello',
            icon: 'hammer',
            name: 'hello',
            title: '你好',
            children: [
                { path: 'index', title: '你好', name: 'hello_index' },
                { path: 'index1', title: '你好1', name: 'hello_index1' }
            ]
        },
        {
            path: '/hello1',
            icon: 'hammer',
            name: 'hello1',
            title: '你好',
            children: [
                { path: 'index2', title: '你好2', name: 'hello_index2' },
                { path: 'index3', title: '你好3', name: 'hello_index3' },
                { path: 'index4', title: '你好3', name: 'hello_index4' }
            ]
        },
        {
            path: '/hello2',
            icon: 'hammer',
            name: 'hello2',
            title: '你好',
            children: [
                { path: 'index4', title: '你好4', name: 'hello_index4' },
                { path: 'index5', title: '你好5', name: 'hello_index5' }
            ]
        }
    ]
    let routernone = [
        {
            path: '/hello2',
            children: []
        },
        {
            path: '/hello1',
            children: [
                'index2', 'index3'
            ]
        }
    ];
    请问如何在 router 以 routernone 为规则 筛选出新数组,routernone中表明,不取path为'/hello2'的,不取path为'/hello1'的children中 path为index2的和path为index3的,
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 大幻想家 普通会员 1楼

      在JavaScript中,你可以使用filter()方法来筛选数组中的对象。filter()方法接收一个函数,该函数用于检查数组中的每个元素是否应该被包含在结果中。你可以使用箭头函数来简化代码。

      以下是一个例子:

      javascript let array = [1, 2, 3, 4, 5]; let filteredArray = array.filter(function(item) { return item > 3; // 这是一个简单的方法,它检查每个元素是否大于3 }); console.log(filteredArray); // 输出 [4, 5]

      在这个例子中,filter()方法接收一个函数作为参数。这个函数被应用到数组的每个元素上,如果该元素大于3,那么该元素就会被包含在结果中。

      你可以根据你的需求更改filter()方法的函数。例如,你可以使用map()方法来创建一个新的数组,其中包含筛选后的元素。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部