js、jq使用大全

1、js遍历输出对象的属性名

 for (var key in obj) {
        console.log(key);
    }

2、JQ   判断div是否存在在某个div内

3、两个集合遍历返回新集合

let arr = [{
				id: 'aa',
				title: '哈哈哈',
				childList: [{
					id: 'aa1',
					title: '哈哈哈1',
					val: '值1'
				}, ]
			},
			{
				id: 'bb',
				title: '哈哈哈1',
				childList: [{
					id: 'bb1',
					title: '哈哈哈1',
					val: '值2'
				}]
			},
		]
		var res = ['值2'];
		let filterPage = arr.map(item => ({
			...item,
			childList: item.childList.map(child => ({
				...child,
				isShow: res.includes(child.val)
			}))
		}));

		最终返回filterPage 为
			[{
				id: 'aa',
				title: '哈哈哈',
				childList: [{
					id: 'aa1',
					title: '哈哈哈1',
					val: '值1',
					isShow: false
				}, ]
			}, {
				id: 'bb',
				title: '哈哈哈1',
				childList: [{
					id: 'bb1',
					title: '哈哈哈1',
					val: '值2',
					isShow: true
				}]
			}, ]

你可能感兴趣的:(javascript,前端,1024程序员节)