Skip to main content

Remove Row

Removes a specific row from a DataTable by its zero-based index. The row is permanently deleted, and subsequent rows shift up to fill the gap.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Input

  • Table - DataTable to remove the row from
  • Row Index - Zero-based index of the row to remove (0 = first row, 1 = second row, etc.)

Output

  • Table - Updated DataTable with the specified row removed

Behavior

  • The row at the specified index is permanently deleted
  • Rows below the removed row shift up (their indices decrease by 1)
  • Total row count decreases by 1
  • Column structure remains unchanged

Example Usage

Removing a Specific Row

// Table with 5 rows (indices 0-4)
// Row 0: ["John", 30]
// Row 1: ["Jane", 25]
// Row 2: ["Bob", 35]
// Row 3: ["Alice", 28]
// Row 4: ["Charlie", 32]

var rowIndex = 2; // Remove Bob's row

// Result: 4 rows
// Row 0: ["John", 30]
// Row 1: ["Jane", 25]
// Row 2: ["Alice", 28] <- shifted up
// Row 3: ["Charlie", 32] <- shifted up

Removing the First Row

// Remove header or first data row
var rowIndex = 0;

// All subsequent rows shift up by 1

Removing the Last Row

// Get last row index
var rowCount = 10; // Assume table has 10 rows
var rowIndex = rowCount - 1; // 9 (last row)

// Remove last row

Conditional Row Removal

// Get row first to check condition
var rowIndex = 5;
var row = /* Get Row at index 5 */;

if (row["Status"] === "Deleted") {
// Remove this row
// Remove Row node with rowIndex = 5
}

Removing Invalid Data

// Process table to find and remove invalid rows
var rowsToCheck = 100;

for (var i = rowsToCheck - 1; i >= 0; i--) { // Process in reverse
var row = /* Get Row at index i */;

// Check for invalid data
if (row["Email"] === "" || row["Email"] === null) {
// Remove this row
var rowIndex = i;
// Remove Row node
}
}

Removing Duplicates

// Find and remove duplicate rows
var processedEmails = [];
var tableSize = 50;

for (var i = tableSize - 1; i >= 0; i--) { // Reverse order important!
var row = /* Get Row at index i */;
var email = row["Email"];

if (processedEmails.indexOf(email) !== -1) {
// Duplicate found - remove it
var rowIndex = i;
// Remove Row node
} else {
processedEmails.push(email);
}
}

Batch Row Removal

// Remove multiple specific rows
// Important: Remove from highest index to lowest
var rowsToRemove = [15, 10, 5, 2]; // Already sorted descending

for (var i = 0; i < rowsToRemove.length; i++) {
var rowIndex = rowsToRemove[i];
// Remove Row node
// Processing in descending order prevents index shifting issues
}

Tips

  • Row indices are zero-based: first row is index 0
  • When removing multiple rows, process from highest index to lowest
  • This prevents index shifting issues during iteration
  • The removal is permanent - the data cannot be recovered
  • Consider backing up important data before removing rows
  • For removing rows based on conditions, use Filter DataTable instead
  • Row removal doesn't affect column structure
  • After removal, subsequent row indices shift down

Common Errors

Empty Table Error

Error: Table cannot be empty. Please provide a valid DataTable.

Solution: Ensure you're passing a valid DataTable object.

// Wrong
var table = null;

// Correct
var table = /* Valid DataTable */;

Negative Row Index Error

Error: Row index must be greater than or equal to zero. Current value: -1

Solution: Provide a non-negative row index.

// Wrong
var rowIndex = -1;

// Correct
var rowIndex = 0; // First row

Index Out of Bounds Error

If the row index exceeds the number of rows in the table, you'll get an error.

// Table has 10 rows (indices 0-9)

// Wrong - index too large
var rowIndex = 10; // Error!

// Correct
var rowIndex = 9; // Last row

Solution: Ensure the row index is less than the total row count.

var table = /* DataTable */;
var rowCount = table.rows.length;
var rowIndex = 5;

if (rowIndex >= 0 && rowIndex < rowCount) {
// Safe to remove
// Remove Row node
} else {
console.log("Invalid row index: " + rowIndex);
}

Removing from Empty Table

Attempting to remove a row from an empty table will cause an error.

// Table with 0 rows
var rowIndex = 0;
// Error: No rows to remove

// Solution: Check row count first
if (table.rows.length > 0) {
// Remove Row node
}

Important: Index Shifting

When removing rows in a loop, indices shift. Always process in reverse order:

Wrong Approach (Forward Iteration)

// This will cause issues!
var rowsToRemove = [2, 5, 8];

for (var i = 0; i < rowsToRemove.length; i++) {
var rowIndex = rowsToRemove[i];
// Remove Row
// After removing row 2, what was row 5 is now row 4!
}

Correct Approach (Reverse Iteration)

// Correct: Remove from highest to lowest index
var rowsToRemove = [8, 5, 2]; // Descending order

for (var i = 0; i < rowsToRemove.length; i++) {
var rowIndex = rowsToRemove[i];
// Remove Row
// No index shifting issues
}

Correct Approach (Reverse Loop)

// Process all rows from bottom to top
var rowCount = 20;

for (var i = rowCount - 1; i >= 0; i--) {
var row = /* Get Row at index i */;

if (/* condition to remove */) {
var rowIndex = i;
// Remove Row
}
}

Alternative: Filter DataTable

For removing multiple rows based on conditions, consider using Filter DataTable instead:

// Instead of removing rows one by one
// Use Filter DataTable with inverse condition

// Remove all rows where Status = "Inactive"
// Filter: "NOT Status = 'Inactive'"
// or
// Filter: "Status = 'Active'"

// This is more efficient than multiple Remove Row operations

See Also