Categories

Remove By Predicate

Remove items that match a predicate using lodash _.remove

Remove items from an array when they match the selected predicate.

Highlights:

  • Uses lodash _.remove
  • Supports numeric and string comparisons
  • Returns the remaining array as JSON

Example:

  • Array: [1, 2, 3, 4]
  • Predicate: greater-than
  • Compare: 2
  • Result: [1, 2]

Enter a JSON array

Select the condition for removal

Value to compare against (required for most predicates)

Key Facts

Category
Data Processing
Input Types
textarea, select, text
Output Type
text
Sample Coverage
4
API Ready
Yes

Overview

The Remove By Predicate tool uses lodash's _.remove function to filter out elements from a JSON array based on specified conditions. It supports numeric and string comparisons, enabling quick data cleaning and preprocessing by returning the remaining array as JSON.

When to Use

  • When you need to remove specific items from an array based on a condition like greater-than or string-contains.
  • For data cleaning tasks, such as eliminating outliers, null values, or invalid entries from datasets.
  • To preprocess arrays before further analysis, transformation, or integration into other workflows.

How It Works

  • Input a valid JSON array in the provided text area.
  • Select a predicate type from the dropdown, such as 'greater-than' or 'string-contains'.
  • Enter a compare value if required by the predicate (e.g., a number or string).
  • The tool processes the array using lodash _.remove and outputs the filtered array as JSON.

Use Cases

Cleaning data by removing null, undefined, or falsey values from an array.
Filtering numerical lists to exclude values outside a specified range, such as removing outliers.
Selecting strings that contain, start with, or end with specific substrings for text processing tasks.

Examples

1. Remove Numbers Above a Threshold

Data Analyst
Background
You have an array of test scores and want to remove all scores above 100 to focus on lower performers for analysis.
Problem
Manually filtering large arrays is time-consuming and prone to errors.
How to Use
Enter the array of scores, select 'greater-than' as the predicate, and set the compare value to 100.
Outcome
The tool returns an array with all scores less than or equal to 100, ready for further statistical review.

2. Filter Strings by Substring

Content Manager
Background
You have a list of article titles and need to remove those that don't contain a specific keyword for SEO optimization.
Problem
Searching through titles manually is inefficient and slows down content curation.
How to Use
Input the array of titles, choose 'string-contains' as the predicate, and enter the keyword as the compare value.
Outcome
The resulting array contains only titles that include the specified keyword, streamlining the selection process.

Try with Samples

json, video

Related Hubs

FAQ

What predicates are supported?

The tool supports predicates like less-than, greater-than, equals, not-equals, string-contains, string-starts-with, string-ends-with, is-nullish, is-truthy, and is-falsey.

Is the compare value always required?

No, for predicates like is-nullish, is-truthy, or is-falsey, the compare value is not needed.

Can I use this tool with arrays of objects?

The tool is designed for arrays of primitive values like numbers or strings. For objects, extract specific properties first.

What happens if the array is empty?

The tool will return an empty array as the result, with no elements removed.

Does the tool modify the original array?

No, it returns a new array with matching elements removed, leaving the original input unchanged.

API Documentation

Request Endpoint

POST /en/api/tools/remove-by-predicate

Request Parameters

Parameter Name Type Required Description
array textarea Yes Enter a JSON array
predicateType select Yes Select the condition for removal
compareValue text No Value to compare against (required for most predicates)

Response Format

{
  "result": "Processed text content",
  "error": "Error message (optional)",
  "message": "Notification message (optional)",
  "metadata": {
    "key": "value"
  }
}
Text: Text

AI MCP Documentation

Add this tool to your MCP server configuration:

{
  "mcpServers": {
    "elysiatools-remove-by-predicate": {
      "name": "remove-by-predicate",
      "description": "Remove items that match a predicate using lodash _.remove",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=remove-by-predicate",
      "command": "",
      "args": [],
      "env": {},
      "isActive": true,
      "type": "sse"
    }
  }
}

You can chain multiple tools, e.g.: `https://elysiatools.com/mcp/sse?toolId=png-to-webp,jpg-to-webp,gif-to-webp`, max 20 tools.

If you encounter any issues, please contact us at [email protected]