How to break or return from DataTable() each() function

How to break or return from DataTable() each() function

jkrishnajkrishna Posts: 3Questions: 1Answers: 0

In my DataTable one of the column as unique values , I want to iterate through the column to find the one of the unique value & get the rowIndex , I tried using each() , I am able to get the rowIndex of the matched column value , but could not break the loop using return statement , is there any other way to break the each() function when a condition is met .I have 10,000 records so the each() function is iteration the 10000 records even when a match is found in 5th record.

Ref: https://datatables.net/reference/api/each()
Test code:

var count=0;
var temp="10021"
var table = $('#example').DataTable();
    table.column( 0 ).data().each( function ( value, index ) {
    count++;
    if(value == temp)
        { console.log("matched rowIndex"+index); return true;   
        }

} );
console.log("count="+" count)

I always get count=10000 , even the matched column rowIndex is 5.

This question has accepted answers - jump to:

Answers

This discussion has been closed.