Make filter on loaded bank variable in javascript [closed]

0

I have a variable, which brings me all the data in the database. There is, as in javascript, I do a filter on it yet, like it brings me 10 tuples and by the only one filter. Before anyone says to do this in the bank, I would like to know if you can do this in javascript, just for learning.

Edit:

As it was not clear, I will clarify. Is there a way to filter a recordset with javascript? Sérgio answered me by array and filter.
That was the question. Is there a way to make a filter in a recordset using pure javascript? Classic asp recordset.

    
asked by anonymous 28.09.2015 / 22:21

1 answer

2

The answer is yes.

It depends a little on how you have the data but the function .filter() works with Arrays. If you have an array all ok, you do not have to use Object.keys(teuObjeto).filter( and iterate the keys of that object.

How to filter?

The function that is passed to the method .filter() must have a return . If this return gives true result (Boolean value) then this element stays, if false then it is deleted.

Example;

var arrayExemplo = [1, 2, 3, 'foo'];

var novaArray = arrayExemplo.filter(function(elemento, index){
    return typeof elemento == 'string';
});

Result:

console.log(novaArray); // dá ['foo']

In other words, it has filtered elements of the not array.

Another radical example would be:

var novaArray = arrayExemplo.filter(function(elemento, index){
    return false;
});

This example gives an empty array ( [] ) because all results give false .

    
28.09.2015 / 22:28