
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
array-tree-filter
Advanced tools
The array-tree-filter npm package is used to filter tree structures in JavaScript arrays. It allows you to traverse and filter nodes in a tree-like array based on a predicate function.
Filter Tree Nodes
This feature allows you to filter nodes in a tree structure based on a predicate function. In this example, the tree is filtered to include only nodes whose value contains '1'.
const arrayTreeFilter = require('array-tree-filter');
const tree = [
{
value: '1',
children: [
{ value: '1.1', children: [{ value: '1.1.1' }] },
{ value: '1.2' }
]
},
{ value: '2', children: [{ value: '2.1' }] }
];
const result = arrayTreeFilter(tree, (item, level) => item.value.indexOf('1') > -1);
console.log(result);
Lodash is a popular utility library that provides a wide range of functions for manipulating arrays, objects, and other data structures. It includes functions like `_.filter` and `_.map` that can be used to traverse and filter tree structures, although it does not provide a dedicated tree filtering function like array-tree-filter.
Treeify is a library that converts a flat array of nodes into a tree structure. While it focuses on creating tree structures rather than filtering them, it can be used in conjunction with other libraries to achieve similar functionality to array-tree-filter.
Flat-tree is a library for working with binary trees in a flat array representation. It provides functions for traversing and manipulating tree structures, but it is more specialized for binary trees and does not offer the same general-purpose tree filtering capabilities as array-tree-filter.
Filter and traverse nested hierarchical tree structures.
import arrayTreeFilter from 'array-tree-filter';
const data = [{
value: 'a',
children: [{
value: 'b',
children: [{
value: 'c'
}, {
value: 'd',
}]
}],
}];
const values = ['a', 'b', 'c'];
const result = arrayTreeFilter(
data, (item, level) => item.value === values[level]
);
console.log(result);
// [
// { value: 'a', children: [...] },
// { value: 'b', children: [...] },
// { value: 'c', children: [...] }
// ]
FAQs
filter in array tree
The npm package array-tree-filter receives a total of 899,328 weekly downloads. As such, array-tree-filter popularity was classified as popular.
We found that array-tree-filter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.