Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent method in Angular 2 of Angular $.grep() method?

How can I refactor this code using angular 2 methods? I could not find anything on google.

var tooltipsData = $.grep(tooltips, function (element, index) {
    return (element.ProductCode == ProductCode);
});
like image 321
Adrian Moisa Avatar asked Dec 04 '25 21:12

Adrian Moisa


1 Answers

Looks like what you really are trying to do is implement that without jQuery (Angular 2 is still just JavaScript (or TypeScript)). If you are trying to implement it in JS, use the Array.filter function

var tooltipsData = tooltips.filter(function (element, index) {
   return (element.ProductCode === ProductCode);
});
like image 170
Michele Ricciardi Avatar answered Dec 06 '25 11:12

Michele Ricciardi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!